evolution-3.6.4/widgets/text/e-reflow-model.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-reflow-model.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-reflow-model.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
  1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
  2 /*
  3  *
  4  * This program is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU Lesser General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2 of the License, or (at your option) version 3.
  8  *
  9  * This program is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  * Lesser General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU Lesser General Public
 15  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 16  *
 17  *
 18  * Authors:
 19  *		Chris Lahey <clahey@ximian.com>
 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 "e-util/e-util.h"
 29 
 30 #include "e-reflow-model.h"
 31 
 32 G_DEFINE_TYPE (EReflowModel, e_reflow_model, G_TYPE_OBJECT)
 33 
 34 #define d(x)
 35 
 36 d (static gint depth = 0;)
 37 
 38 enum {
 39 	MODEL_CHANGED,
 40 	COMPARISON_CHANGED,
 41 	MODEL_ITEMS_INSERTED,
 42 	MODEL_ITEM_CHANGED,
 43 	MODEL_ITEM_REMOVED,
 44 	LAST_SIGNAL
 45 };
 46 
 47 static guint signals[LAST_SIGNAL] = { 0, };
 48 
 49 /**
 50  * e_reflow_model_set_width:
 51  * @e_reflow_model: The e-reflow-model to operate on
 52  * @width: The new value for the width of each item.
 53  */
 54 void
 55 e_reflow_model_set_width (EReflowModel *e_reflow_model,
 56                           gint width)
 57 {
 58 	EReflowModelClass *class;
 59 
 60 	g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model));
 61 
 62 	class = E_REFLOW_MODEL_GET_CLASS (e_reflow_model);
 63 	g_return_if_fail (class->set_width != NULL);
 64 
 65 	class->set_width (e_reflow_model, width);
 66 }
 67 
 68 /**
 69  * e_reflow_model_count:
 70  * @e_reflow_model: The e-reflow-model to operate on
 71  *
 72  * Returns: the number of items in the reflow model.
 73  */
 74 gint
 75 e_reflow_model_count (EReflowModel *e_reflow_model)
 76 {
 77 	EReflowModelClass *class;
 78 
 79 	g_return_val_if_fail (E_IS_REFLOW_MODEL (e_reflow_model), 0);
 80 
 81 	class = E_REFLOW_MODEL_GET_CLASS (e_reflow_model);
 82 	g_return_val_if_fail (class->count != NULL, 0);
 83 
 84 	return class->count (e_reflow_model);
 85 }
 86 
 87 /**
 88  * e_reflow_model_height:
 89  * @e_reflow_model: The e-reflow-model to operate on
 90  * @n: The item number to get the height of.
 91  * @parent: The parent GnomeCanvasItem.
 92  *
 93  * Returns: the height of the nth item.
 94  */
 95 gint
 96 e_reflow_model_height (EReflowModel *e_reflow_model,
 97                        gint n,
 98                        GnomeCanvasGroup *parent)
 99 {
100 	EReflowModelClass *class;
101 
102 	g_return_val_if_fail (E_IS_REFLOW_MODEL (e_reflow_model), 0);
103 
104 	class = E_REFLOW_MODEL_GET_CLASS (e_reflow_model);
105 	g_return_val_if_fail (class->height != NULL, 0);
106 
107 	return class->height (e_reflow_model, n, parent);
108 }
109 
110 /**
111  * e_reflow_model_incarnate:
112  * @e_reflow_model: The e-reflow-model to operate on
113  * @n: The item to create.
114  * @parent: The parent GnomeCanvasItem to create a child of.
115  *
116  * Create a GnomeCanvasItem to represent the nth piece of data.
117  *
118  * Returns: the new GnomeCanvasItem.
119  */
120 GnomeCanvasItem *
121 e_reflow_model_incarnate (EReflowModel *e_reflow_model,
122                           gint n,
123                           GnomeCanvasGroup *parent)
124 {
125 	EReflowModelClass *class;
126 
127 	g_return_val_if_fail (E_IS_REFLOW_MODEL (e_reflow_model), NULL);
128 
129 	class = E_REFLOW_MODEL_GET_CLASS (e_reflow_model);
130 	g_return_val_if_fail (class->incarnate != NULL, NULL);
131 
132 	return class->incarnate (e_reflow_model, n, parent);
133 }
134 
135 /**
136  * e_reflow_model_create_cmp_cache:
137  * @e_reflow_model: The e-reflow-model to operate on
138  *
139  * Creates a compare cache for quicker sorting. The sorting function
140  * may not depend on the cache, but it should benefit from it if available.
141  *
142  * Returns: Newly created GHashTable with cached compare values. This will be
143  * automatically freed with g_hash_table_destroy() when no longer needed.
144  **/
145 GHashTable *
146 e_reflow_model_create_cmp_cache (EReflowModel *e_reflow_model)
147 {
148 	EReflowModelClass *class;
149 
150 	g_return_val_if_fail (E_IS_REFLOW_MODEL (e_reflow_model), NULL);
151 
152 	class = E_REFLOW_MODEL_GET_CLASS (e_reflow_model);
153 
154 	if (class->create_cmp_cache == NULL)
155 		return NULL;
156 
157 	return class->create_cmp_cache (e_reflow_model);
158 }
159 
160 /**
161  * e_reflow_model_compare:
162  * @e_reflow_model: The e-reflow-model to operate on
163  * @n1: The first item to compare
164  * @n2: The second item to compare
165  * @cmp_cache: #GHashTable of cached compare values, created by
166  *    e_reflow_model_create_cmp_cache(). This can be NULL, when
167  *    caching is not available, even when @e_reflow_model defines
168  *    the create_cmp_cache function.
169  *
170  * Compares item n1 and item n2 to see which should come first.
171  *
172  * Returns: strcmp like semantics for the comparison value.
173  */
174 gint
175 e_reflow_model_compare (EReflowModel *e_reflow_model,
176                         gint n1,
177                         gint n2,
178                         GHashTable *cmp_cache)
179 {
180 	EReflowModelClass *class;
181 
182 	g_return_val_if_fail (E_IS_REFLOW_MODEL (e_reflow_model), 0);
183 
184 	class = E_REFLOW_MODEL_GET_CLASS (e_reflow_model);
185 	g_return_val_if_fail (class->compare != NULL, 0);
186 
187 	return class->compare (e_reflow_model, n1, n2, cmp_cache);
188 }
189 
190 /**
191  * e_reflow_model_reincarnate:
192  * @e_reflow_model: The e-reflow-model to operate on
193  * @n: The item to create.
194  * @item: The item to reuse.
195  *
196  * Update item to represent the nth piece of data.
197  */
198 void
199 e_reflow_model_reincarnate (EReflowModel *e_reflow_model,
200                             gint n,
201                             GnomeCanvasItem *item)
202 {
203 	EReflowModelClass *class;
204 
205 	g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model));
206 
207 	class = E_REFLOW_MODEL_GET_CLASS (e_reflow_model);
208 	g_return_if_fail (class->reincarnate != NULL);
209 
210 	class->reincarnate (e_reflow_model, n, item);
211 }
212 
213 static void
214 e_reflow_model_class_init (EReflowModelClass *class)
215 {
216 	GObjectClass *object_class = G_OBJECT_CLASS (class);
217 
218 	class->set_width            = NULL;
219 	class->count                = NULL;
220 	class->height               = NULL;
221 	class->incarnate            = NULL;
222 	class->reincarnate          = NULL;
223 
224 	class->model_changed        = NULL;
225 	class->comparison_changed   = NULL;
226 	class->model_items_inserted = NULL;
227 	class->model_item_removed   = NULL;
228 	class->model_item_changed   = NULL;
229 
230 	signals[MODEL_CHANGED] = g_signal_new (
231 		"model_changed",
232 		G_OBJECT_CLASS_TYPE (object_class),
233 		G_SIGNAL_RUN_LAST,
234 		G_STRUCT_OFFSET (EReflowModelClass, model_changed),
235 		NULL, NULL,
236 		g_cclosure_marshal_VOID__VOID,
237 		G_TYPE_NONE, 0);
238 
239 	signals[COMPARISON_CHANGED] = g_signal_new (
240 		"comparison_changed",
241 		G_OBJECT_CLASS_TYPE (object_class),
242 		G_SIGNAL_RUN_LAST,
243 		G_STRUCT_OFFSET (EReflowModelClass, comparison_changed),
244 		NULL, NULL,
245 		g_cclosure_marshal_VOID__VOID,
246 		G_TYPE_NONE, 0);
247 
248 	signals[MODEL_ITEMS_INSERTED] = g_signal_new (
249 		"model_items_inserted",
250 		G_OBJECT_CLASS_TYPE (object_class),
251 		G_SIGNAL_RUN_LAST,
252 		G_STRUCT_OFFSET (EReflowModelClass, model_items_inserted),
253 		NULL, NULL,
254 		e_marshal_NONE__INT_INT,
255 		G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
256 
257 	signals[MODEL_ITEM_CHANGED] = g_signal_new (
258 		"model_item_changed",
259 		G_OBJECT_CLASS_TYPE (object_class),
260 		G_SIGNAL_RUN_LAST,
261 		G_STRUCT_OFFSET (EReflowModelClass, model_item_changed),
262 		NULL, NULL,
263 		g_cclosure_marshal_VOID__INT,
264 		G_TYPE_NONE, 1, G_TYPE_INT);
265 
266 	signals[MODEL_ITEM_REMOVED] = g_signal_new (
267 		"model_item_removed",
268 		G_OBJECT_CLASS_TYPE (object_class),
269 		G_SIGNAL_RUN_LAST,
270 		G_STRUCT_OFFSET (EReflowModelClass, model_item_removed),
271 		NULL, NULL,
272 		g_cclosure_marshal_VOID__INT,
273 		G_TYPE_NONE, 1, G_TYPE_INT);
274 }
275 
276 static void
277 e_reflow_model_init (EReflowModel *e_reflow_model)
278 {
279 }
280 
281 #if d(!)0
282 static void
283 print_tabs (void)
284 {
285 	gint i;
286 	for (i = 0; i < depth; i++)
287 		g_print ("\t");
288 }
289 #endif
290 
291 /**
292  * e_reflow_model_changed:
293  * @e_reflow_model: the reflow model to notify of the change
294  *
295  * Use this function to notify any views of this reflow model that
296  * the contents of the reflow model have changed.  This will emit
297  * the signal "model_changed" on the @e_reflow_model object.
298  *
299  * It is preferable to use the e_reflow_model_item_changed() signal to
300  * notify of smaller changes than to invalidate the entire model, as
301  * the views might have ways of caching the information they render
302  * from the model.
303  */
304 void
305 e_reflow_model_changed (EReflowModel *e_reflow_model)
306 {
307 	g_return_if_fail (e_reflow_model != NULL);
308 	g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model));
309 
310 	d (print_tabs ());
311 	d (g_print ("Emitting model_changed on model 0x%p.\n", e_reflow_model));
312 	d (depth++);
313 	g_signal_emit (e_reflow_model, signals[MODEL_CHANGED], 0);
314 	d (depth--);
315 }
316 
317 /**
318  * e_reflow_model_comparison_changed:
319  * @e_reflow_model: the reflow model to notify of the change
320  *
321  * Use this function to notify any views of this reflow model that the
322  * sorting has changed.  The actual contents of the items hasn't, so
323  * there's no need to re-query the model for the heights of the
324  * individual items.
325  */
326 void
327 e_reflow_model_comparison_changed (EReflowModel *e_reflow_model)
328 {
329 	g_return_if_fail (e_reflow_model != NULL);
330 	g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model));
331 
332 	d (print_tabs ());
333 	d (g_print (
334 		"Emitting comparison_changed on model 0x%p.\n",
335 		e_reflow_model));
336 	d (depth++);
337 	g_signal_emit (e_reflow_model, signals[COMPARISON_CHANGED], 0);
338 	d (depth--);
339 }
340 
341 /**
342  * e_reflow_model_items_inserted:
343  * @e_reflow_model: The model changed.
344  * @position: The position the items were insert in.
345  * @count: The number of items inserted.
346  *
347  * Use this function to notify any views of the reflow model that a number
348  * of items have been inserted.
349  **/
350 void
351 e_reflow_model_items_inserted (EReflowModel *e_reflow_model,
352                                gint position,
353                                gint count)
354 {
355 	g_return_if_fail (e_reflow_model != NULL);
356 	g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model));
357 
358 	d (print_tabs ());
359 	d (depth++);
360 	g_signal_emit (
361 		e_reflow_model,
362 		signals[MODEL_ITEMS_INSERTED], 0,
363 		position, count);
364 	d (depth--);
365 }
366 
367 /**
368  * e_reflow_model_item_removed:
369  * @e_reflow_model: The model changed.
370  * @n: The position from which the items were removed.
371  *
372  * Use this function to notify any views of the reflow model that an
373  * item has been removed.
374  **/
375 void
376 e_reflow_model_item_removed (EReflowModel *e_reflow_model,
377                              gint n)
378 {
379 	g_return_if_fail (e_reflow_model != NULL);
380 	g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model));
381 
382 	d (print_tabs ());
383 	d (depth++);
384 	g_signal_emit (e_reflow_model, signals[MODEL_ITEM_REMOVED], 0, n);
385 	d (depth--);
386 }
387 
388 /**
389  * e_reflow_model_item_changed:
390  * @e_reflow_model: the reflow model to notify of the change
391  * @item: the item that was changed in the model.
392  *
393  * Use this function to notify any views of the reflow model that the
394  * contents of item @item have changed in model such that the height
395  * has changed or the item needs to be reincarnated.  This function
396  * will emit the "model_item_changed" signal on the @e_reflow_model
397  * object
398  */
399 void
400 e_reflow_model_item_changed (EReflowModel *e_reflow_model,
401                              gint n)
402 {
403 	g_return_if_fail (e_reflow_model != NULL);
404 	g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model));
405 
406 	d (print_tabs ());
407 	d (g_print ("Emitting item_changed on model 0x%p, n=%d.\n", e_reflow_model, n));
408 	d (depth++);
409 	g_signal_emit (e_reflow_model, signals[MODEL_ITEM_CHANGED], 0, n);
410 	d (depth--);
411 }