1 /*   EXTRAITS DE LA LICENCE
2 	Copyright CEA, contributeurs : Luc BILLARD et Damien
3 	CALISTE, laboratoire L_Sim, (2001-2005)
4 
5 	Adresse mèl :
6 	BILLARD, non joignable par mèl ;
7 	CALISTE, damien P caliste AT cea P fr.
8 
9 	Ce logiciel est un programme informatique servant à visualiser des
10 	structures atomiques dans un rendu pseudo-3D.
11 
12 	Ce logiciel est régi par la licence CeCILL soumise au droit français et
13 	respectant les principes de diffusion des logiciels libres. Vous pouvez
14 	utiliser, modifier et/ou redistribuer ce programme sous les conditions
15 	de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
16 	sur le site "http://www.cecill.info".
17 
18 	Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
19 	pris connaissance de la licence CeCILL, et que vous en avez accepté les
20 	termes (cf. le fichier Documentation/licence.fr.txt fourni avec ce logiciel).
21 */
22 
23 /*   LICENCE SUM UP
24 	Copyright CEA, contributors : Luc BILLARD et Damien
25 	CALISTE, laboratoire L_Sim, (2001-2005)
26 
27 	E-mail address:
28 	BILLARD, not reachable any more ;
29 	CALISTE, damien P caliste AT cea P fr.
30 
31 	This software is a computer program whose purpose is to visualize atomic
32 	configurations in 3D.
33 
34 	This software is governed by the CeCILL  license under French law and
35 	abiding by the rules of distribution of free software.  You can  use,
36 	modify and/ or redistribute the software under the terms of the CeCILL
37 	license as circulated by CEA, CNRS and INRIA at the following URL
38 	"http://www.cecill.info".
39 
40 	The fact that you are presently reading this means that you have had
41 	knowledge of the CeCILL license and that you accept its terms. You can
42 	find a copy of this licence shipped with this software at Documentation/licence.en.txt.
43 */
44 #include <gtk/gtk.h>
45 
46 #include "gtk_stippleComboBoxWidget.h"
47 #include <visu_tools.h>
48 
49 /**
50  * SECTION:gtk_stippleComboBoxWidget
51  * @short_description: Defines a specialised #GtkComboBox to choose
52  * patterns for lines.
53  * @see_also: #VisuUiShadeCombobox
54  *
55  * <para>This widget looks like a #GtkComboBox and it displays a list
56  * of preset patterns for line. These patterns are defined by a
57  * guint16 value that is given to OpenGL for line stipple.</para>
58  * <para>This widget can emit a #VisuUiStippleCombobox::stipple-selected
59  * signal that is a wrapper around the #GtkComboBox::changed signal,
60  * but it is emitted only when a stipple is selected and this stipple
61  * is passed to the call back.</para>
62  *
63  * Since: 3.4
64  */
65 
66 enum {
67   STIPPLE_SELECTED_SIGNAL,
68   LAST_SIGNAL
69 };
70 static guint signals[LAST_SIGNAL] = { 0 };
71 
72 enum
73   {
74     PROP_0,
75     VALUE_PROP,
76     N_PROP
77   };
78 static GParamSpec *properties[N_PROP];
79 
80 /* This enum is used to access the column of the GtkListStore
81    that contains the informations of stroed shades. */
82 enum
83   {
84     /* This has a pointer to an image to represent the stipple. */
85     COLUMN_STIPPLE_PIXBUF,
86     /* This is a pointer to a label that describes the stipple. */
87     COLUMN_STIPPLE_LABEL,
88     /* This is the value of the stipple. */
89     COLUMN_STIPPLE_VALUE,
90 
91     N_COLUMN_STIPPLE
92   };
93 
94 /* Store a tree model to remember stipples. */
95 #define STIPPLE_BOX_WIDTH  32
96 #define STIPPLE_BOX_HEIGHT 3
97 #define STIPPLE_BOX_BITS   8
98 
99 static void visu_ui_stipple_combobox_dispose (GObject *obj);
100 static void visu_ui_stipple_combobox_finalize(GObject *obj);
101 static void visu_ui_stipple_combobox_get_property(GObject* obj, guint property_id,
102                                                   GValue *value, GParamSpec *pspec);
103 static void visu_ui_stipple_combobox_set_property(GObject* obj, guint property_id,
104                                                   const GValue *value, GParamSpec *pspec);
105 
106 
107 /**
108  * VisuUiStippleCombobox:
109  *
110  * Private structure to store informations of a #VisuUiStippleCombobox object.
111  *
112  * Since: 3.4
113  */
114 struct _VisuUiStippleCombobox
115 {
116   GtkComboBox comboStipple;
117   guint16 previousStipple;
118 
119   /* Memory gestion. */
120   gboolean dispose_has_run;
121 };
122 /**
123  * VisuUiStippleComboboxClass
124  *
125  * Private structure to store informations of a #VisuUiStippleComboboxClass object.
126  *
127  * Since: 3.4
128  */
129 struct _VisuUiStippleComboboxClass
130 {
131   GtkComboBoxClass parent_class;
132 
133   void (*stippleComboBox) (VisuUiStippleCombobox *stippleCombo);
134 
135   /* This listStore contains all the stipples
136      known by widgets of this class. It is used
137      as TreeModel for the combobox in the widget. */
138   GtkListStore *listStoredStipples;
139 
140   gulong stippleAddedSignalId;
141 };
142 
143 /* Built-in stipple values. */
144 static guint16 builtInStipples[] = {65535, 43690, 52428, 61680, 65280,
145 				    58596, 57568, 49344, 65340, 0};
146 
147 /* Local callbacks. */
148 static void visu_ui_stipple_combobox_changed(VisuUiStippleCombobox *stippleComboBox,
149 				    gpointer data _U_);
150 
151 /* Local methods. */
152 static void addStippleToModel(GtkTreeIter *iter, VisuUiStippleComboboxClass* klass,
153 			      guint16 value);
154 static void buildWidgets(VisuUiStippleCombobox *stippleComboBox);
155 
156 /**
157  * visu_ui_stipple_combobox_get_type
158  *
159  * #GType are unique numbers to identify objects.
160  *
161  * Returns: the #GType associated with #VisuUiStippleCombobox objects.
162  *
163  * Since: 3.4
164  */
G_DEFINE_TYPE(VisuUiStippleCombobox,visu_ui_stipple_combobox,GTK_TYPE_COMBO_BOX)165 G_DEFINE_TYPE(VisuUiStippleCombobox, visu_ui_stipple_combobox, GTK_TYPE_COMBO_BOX)
166 
167 static void visu_ui_stipple_combobox_class_init(VisuUiStippleComboboxClass *klass)
168 {
169   GtkTreeIter iter;
170   int i;
171 
172   DBG_fprintf(stderr, "Gtk VisuUiStippleCombobox: creating the class of the widget.\n");
173   DBG_fprintf(stderr, "                     - adding new signals ;\n");
174   /**
175    * VisuUiStippleCombobox::stipple-selected:
176    * @combo: the #VisuUiStippleCombobox that emits the signal ;
177    * @stipple: the value of the newly selected line patter.
178    *
179    * This signal is emitted when a new valid line pattern is selected.
180    *
181    * Since: 3.4
182    */
183   signals[STIPPLE_SELECTED_SIGNAL] =
184     g_signal_new ("stipple-selected",
185 		  G_TYPE_FROM_CLASS (klass),
186 		  G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
187 		  G_STRUCT_OFFSET (VisuUiStippleComboboxClass, stippleComboBox),
188 		  NULL,
189 		  NULL,
190 		  g_cclosure_marshal_VOID__UINT,
191 		  G_TYPE_NONE, 1, G_TYPE_UINT);
192 
193   DBG_fprintf(stderr, "                     - initializing the listStore of stipples.\n");
194   /* Init the listStore of stipples. */
195   klass->listStoredStipples = gtk_list_store_new(N_COLUMN_STIPPLE,
196 						 GDK_TYPE_PIXBUF,
197 						 G_TYPE_STRING,
198 						 G_TYPE_UINT);
199   for (i = 0; builtInStipples[i]; i++)
200     addStippleToModel(&iter, klass, builtInStipples[i]);
201 
202   /* Connect freeing methods. */
203   G_OBJECT_CLASS(klass)->dispose = visu_ui_stipple_combobox_dispose;
204   G_OBJECT_CLASS(klass)->finalize = visu_ui_stipple_combobox_finalize;
205   G_OBJECT_CLASS(klass)->set_property = visu_ui_stipple_combobox_set_property;
206   G_OBJECT_CLASS(klass)->get_property = visu_ui_stipple_combobox_get_property;
207 
208   /**
209    * VisuUiStippleCombobox::value:
210    *
211    * Store the current stipple.
212    *
213    * Since: 3.8
214    */
215   properties[VALUE_PROP] = g_param_spec_uint("value", "stipple value",
216                                              "stipple pattern for OpenGL",
217                                              0, 65535, (guint)builtInStipples[0],
218                                              G_PARAM_READWRITE);
219   g_object_class_install_property(G_OBJECT_CLASS(klass), VALUE_PROP,
220 				  properties[VALUE_PROP]);
221 }
222 
visu_ui_stipple_combobox_dispose(GObject * obj)223 static void visu_ui_stipple_combobox_dispose(GObject *obj)
224 {
225   DBG_fprintf(stderr, "Gtk VisuUiStippleCombobox: dispose object %p.\n", (gpointer)obj);
226 
227   if (VISU_UI_STIPPLE_COMBOBOX(obj)->dispose_has_run)
228     return;
229 
230   VISU_UI_STIPPLE_COMBOBOX(obj)->dispose_has_run = TRUE;
231   /* Chain up to the parent class */
232   DBG_fprintf(stderr, " | chain to parent\n");
233   G_OBJECT_CLASS(visu_ui_stipple_combobox_parent_class)->dispose(obj);
234   DBG_fprintf(stderr, " | disposing ... OK.\n");
235 }
visu_ui_stipple_combobox_finalize(GObject * obj)236 static void visu_ui_stipple_combobox_finalize(GObject *obj)
237 {
238   g_return_if_fail(obj);
239 
240   DBG_fprintf(stderr, "Gtk VisuUiStippleCombobox: finalize object %p.\n", (gpointer)obj);
241 
242   /* Chain up to the parent class */
243   G_OBJECT_CLASS(visu_ui_stipple_combobox_parent_class)->finalize(obj);
244 
245   DBG_fprintf(stderr, " | freeing ... OK.\n");
246 }
visu_ui_stipple_combobox_get_property(GObject * obj,guint property_id,GValue * value,GParamSpec * pspec)247 static void visu_ui_stipple_combobox_get_property(GObject* obj, guint property_id,
248                                                   GValue *value, GParamSpec *pspec)
249 {
250   guint16 stipple;
251   VisuUiStippleCombobox *self = VISU_UI_STIPPLE_COMBOBOX(obj);
252 
253   DBG_fprintf(stderr, "Gtk VisuUiStippleCombobox: get property '%s' -> ",
254 	      g_param_spec_get_name(pspec));
255   switch (property_id)
256     {
257     case VALUE_PROP:
258       stipple = visu_ui_stipple_combobox_getSelection(self);
259       g_value_set_uint(value, (guint)stipple);
260       DBG_fprintf(stderr, "%d.\n", stipple);
261       break;
262     default:
263       /* We don't have any other property... */
264       G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, property_id, pspec);
265       break;
266     }
267 }
visu_ui_stipple_combobox_set_property(GObject * obj,guint property_id,const GValue * value,GParamSpec * pspec)268 static void visu_ui_stipple_combobox_set_property(GObject* obj, guint property_id,
269                                                   const GValue *value, GParamSpec *pspec)
270 {
271   guint16 stipple;
272   VisuUiStippleCombobox *self = VISU_UI_STIPPLE_COMBOBOX(obj);
273 
274   DBG_fprintf(stderr, "Gtk VisuUiStippleCombobox: set property '%s' -> ",
275 	      g_param_spec_get_name(pspec));
276   switch (property_id)
277     {
278     case VALUE_PROP:
279       stipple = (guint16)g_value_get_uint(value);
280       visu_ui_stipple_combobox_set(self, stipple);
281       DBG_fprintf(stderr, "%d.\n", stipple);
282       break;
283     default:
284       /* We don't have any other property... */
285       G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, property_id, pspec);
286       break;
287     }
288 }
289 
visu_ui_stipple_combobox_init(VisuUiStippleCombobox * stippleComboBox)290 static void visu_ui_stipple_combobox_init(VisuUiStippleCombobox *stippleComboBox)
291 {
292   DBG_fprintf(stderr, "Gtk VisuUiStippleCombobox: initializing new object (%p).\n",
293 	      (gpointer)stippleComboBox);
294 
295   stippleComboBox->previousStipple = (guint16)0;
296   stippleComboBox->dispose_has_run = FALSE;
297 }
298 
buildWidgets(VisuUiStippleCombobox * stippleComboBox)299 static void buildWidgets(VisuUiStippleCombobox *stippleComboBox)
300 {
301   GObjectClass *klass;
302   GtkCellRenderer *renderer;
303 
304   klass = G_OBJECT_GET_CLASS(stippleComboBox);
305   gtk_combo_box_set_model(GTK_COMBO_BOX(stippleComboBox),
306 			  GTK_TREE_MODEL(VISU_UI_STIPPLE_COMBOBOX_CLASS(klass)->listStoredStipples));
307 
308   renderer = gtk_cell_renderer_pixbuf_new();
309   gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(stippleComboBox), renderer, FALSE);
310   gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(stippleComboBox), renderer,
311 				"pixbuf", COLUMN_STIPPLE_PIXBUF);
312 /*   renderer = gtk_cell_renderer_text_new(); */
313 /*   gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(stippleComboBox), renderer, FALSE); */
314 /*   gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(stippleComboBox), renderer, */
315 /* 				"markup", COLUMN_STIPPLE_LABEL); */
316 
317   gtk_combo_box_set_active(GTK_COMBO_BOX(stippleComboBox), 0);
318   g_signal_connect(G_OBJECT(stippleComboBox), "changed",
319 		   G_CALLBACK(visu_ui_stipple_combobox_changed), (gpointer)0);
320 }
321 
322 /**
323  * visu_ui_stipple_combobox_new :
324  *
325  * A #VisuUiStippleCombobox widget is like a #GtkComboBox widget, but it is already filled
326  * with predefined line patterns (call stipple). Using this widget is
327  * a convienient way to share stipples between all part of V_Sim and
328  * to give a consistent look of all stipple selection.
329  *
330  * Returns: (transfer full): a newly created #VisuUiStippleCombobox widget.
331  *
332  * Since: 3.4
333  */
visu_ui_stipple_combobox_new()334 GtkWidget* visu_ui_stipple_combobox_new()
335 {
336   VisuUiStippleCombobox *stippleComboBox;
337 
338   DBG_fprintf(stderr, "Gtk VisuUiStippleCombobox: creating new object.\n");
339 
340   stippleComboBox = VISU_UI_STIPPLE_COMBOBOX(g_object_new(VISU_TYPE_UI_STIPPLE_COMBOBOX, NULL));
341 
342   DBG_fprintf(stderr, "Gtk VisuUiStippleCombobox: build widgets.\n");
343   buildWidgets(stippleComboBox);
344 
345   return GTK_WIDGET(stippleComboBox);
346 }
347 
visu_ui_stipple_combobox_changed(VisuUiStippleCombobox * stippleComboBox,gpointer data _U_)348 static void visu_ui_stipple_combobox_changed(VisuUiStippleCombobox *stippleComboBox,
349                                              gpointer data _U_)
350 {
351   int selected;
352   guint16 stipple;
353 
354   selected = gtk_combo_box_get_active(GTK_COMBO_BOX(stippleComboBox));
355   DBG_fprintf(stderr, "Gtk VisuUiStippleCombobox: internal combobox changed signal -> %d.\n", selected);
356   if (selected < 0)
357     {
358       stippleComboBox->previousStipple = (guint16)0;
359 /*       DBG_fprintf(stderr, "Gtk VisuUiStippleCombobox : emitting 'stipple-selected' signal.\n"); */
360 /*       g_signal_emit(G_OBJECT(stippleComboBox), */
361 /* 		    signals[STIPPLE_SELECTED_SIGNAL], 0, (gpointer)0, NULL); */
362       return;
363     }
364 
365   stipple = visu_ui_stipple_combobox_getSelection(stippleComboBox);
366   if (stipple && stipple != stippleComboBox->previousStipple)
367     {
368       stippleComboBox->previousStipple = stipple;
369       DBG_fprintf(stderr, "Gtk VisuUiStippleCombobox: emitting 'stipple-selected'"
370 		  " signal for value %d.\n", stipple);
371       g_object_notify_by_pspec(G_OBJECT(stippleComboBox), properties[VALUE_PROP]);
372       g_signal_emit(G_OBJECT(stippleComboBox),
373 		    signals[STIPPLE_SELECTED_SIGNAL],
374                     0, (guint)stipple, NULL);
375     }
376   else
377     DBG_fprintf(stderr, "Gtk VisuUiStippleCombobox: aborting 'stipple-selected' signal.\n");
378 }
379 /**
380  * visu_ui_stipple_combobox_class_buildStamp:
381  * @stipple: a pattern value.
382  *
383  * This method is used to create pixbuf representing stipples.A new
384  * pixbuf is created.
385  *
386  * Returns: (transfer full): a pixbuf pointer.
387  *
388  * Since: 3.4
389  */
visu_ui_stipple_combobox_class_buildStamp(guint16 stipple)390 GdkPixbuf* visu_ui_stipple_combobox_class_buildStamp(guint16 stipple)
391 {
392   GdkPixbuf *pixbufStippleBox;
393   int rowstride, x, y;
394   guchar *pixels, *p;
395   guint16 coul;
396 
397   pixbufStippleBox = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE,
398 				    STIPPLE_BOX_BITS,
399 				    STIPPLE_BOX_WIDTH,
400 				    STIPPLE_BOX_HEIGHT);
401   rowstride = gdk_pixbuf_get_rowstride(pixbufStippleBox);
402   pixels = gdk_pixbuf_get_pixels(pixbufStippleBox);
403   for (x = 0; x < STIPPLE_BOX_WIDTH; x++)
404     {
405       coul = stipple & (1 << ((x+3)%16));
406       for (y = 0; y < STIPPLE_BOX_HEIGHT; y++)
407 	{
408 	  p    = pixels + y * rowstride + x * 4;
409 	  p[0] = 0;
410 	  p[1] = 0;
411 	  p[2] = 0;
412 	  p[3] = (coul)?255:0;
413 	}
414     }
415   return pixbufStippleBox;
416 }
417 
addStippleToModel(GtkTreeIter * iter,VisuUiStippleComboboxClass * klass,guint16 stipple)418 void addStippleToModel(GtkTreeIter *iter, VisuUiStippleComboboxClass* klass, guint16 stipple)
419 {
420   GdkPixbuf *pix;
421   gchar *label;
422 
423   g_return_if_fail(iter && klass && stipple);
424 
425   label = g_markup_printf_escaped("<span size=\"smaller\"><i>(%d)</i></span>",
426 				  stipple);
427   pix = visu_ui_stipple_combobox_class_buildStamp(stipple);
428   gtk_list_store_append(klass->listStoredStipples, iter);
429   gtk_list_store_set(klass->listStoredStipples, iter,
430 		     COLUMN_STIPPLE_PIXBUF, pix,
431 		     COLUMN_STIPPLE_LABEL,  label,
432 		     COLUMN_STIPPLE_VALUE,  (guint)stipple,
433 		     -1);
434   g_object_unref(pix);
435   g_free(label);
436   DBG_fprintf(stderr, "Gtk VisuUiStippleCombobox: appending a new stipple '%d'.\n",
437 	      stipple);
438 }
439 /**
440  * visu_ui_stipple_combobox_setSelection:
441  * @stippleComboBox: a #VisuUiStippleCombobox widget ;
442  * @stipple: a pattern value.
443  *
444  * Use this method to set the ComboBox on the given stipple. This emits a 'stipple-channel'
445  * signal if the stipple is changed, which means, a previous stipple has been modified,
446  * or a new stipple is selected.
447  *
448  * Returns: TRUE if the @stipple already exists in the model.
449  *
450  * Since: 3.4
451  */
visu_ui_stipple_combobox_setSelection(VisuUiStippleCombobox * stippleComboBox,guint16 stipple)452 gboolean visu_ui_stipple_combobox_setSelection(VisuUiStippleCombobox* stippleComboBox,
453 					       guint16 stipple)
454 {
455   GtkTreeIter iter;
456   gboolean validIter;
457   GObjectClass *klass;
458   GtkListStore *model;
459   guint tmpStipple;
460 
461   g_return_val_if_fail(stipple && VISU_IS_UI_STIPPLE_COMBOBOX(stippleComboBox), FALSE);
462 
463   DBG_fprintf(stderr, "Gtk VisuUiStippleCombobox: select a new stipple %d.\n", stipple);
464   klass = G_OBJECT_GET_CLASS(stippleComboBox);
465   model = GTK_LIST_STORE(VISU_UI_STIPPLE_COMBOBOX_CLASS(klass)->listStoredStipples);
466   validIter = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter);
467   while (validIter)
468     {
469       gtk_tree_model_get(GTK_TREE_MODEL(model), &iter,
470 			 COLUMN_STIPPLE_VALUE, &tmpStipple,
471 			 -1);
472       if ((guint16)(tmpStipple) == stipple)
473 	{
474 	  gtk_combo_box_set_active_iter(GTK_COMBO_BOX(stippleComboBox), &iter);
475 	  return TRUE;
476 	}
477       validIter = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter);
478     }
479   return FALSE;
480 }
stippleComboBoxGet_selectedPixbuf(VisuUiStippleCombobox * stippleComboBox)481 GdkPixbuf* stippleComboBoxGet_selectedPixbuf(VisuUiStippleCombobox *stippleComboBox)
482 {
483   gboolean validIter;
484   GtkTreeIter iter;
485   GdkPixbuf *pixbuf;
486   GObjectClass *klass;
487 
488   g_return_val_if_fail(VISU_IS_UI_STIPPLE_COMBOBOX(stippleComboBox), (GdkPixbuf*)0);
489 
490   validIter = gtk_combo_box_get_active_iter(GTK_COMBO_BOX(stippleComboBox), &iter);
491   if (!validIter)
492     return (GdkPixbuf*)0;
493 
494   pixbuf = (GdkPixbuf*)0;
495   klass = G_OBJECT_GET_CLASS(stippleComboBox);
496   gtk_tree_model_get(GTK_TREE_MODEL(VISU_UI_STIPPLE_COMBOBOX_CLASS(klass)->listStoredStipples), &iter,
497 		     COLUMN_STIPPLE_PIXBUF, &pixbuf,
498 		     -1);
499   return pixbuf;
500 }
501 /**
502  * visu_ui_stipple_combobox_getSelection:
503  * @stippleComboBox: a #VisuUiStippleCombobox widget.
504  *
505  * The user can access to the selected stipple pattern using this method.
506  *
507  * Returns: a pattern value (or 65535).
508  *
509  * Since: 3.4
510  */
visu_ui_stipple_combobox_getSelection(VisuUiStippleCombobox * stippleComboBox)511 guint16 visu_ui_stipple_combobox_getSelection(VisuUiStippleCombobox *stippleComboBox)
512 {
513   gboolean validIter;
514   GtkTreeIter iter;
515   guint stipple;
516   GObjectClass *klass;
517 
518   g_return_val_if_fail(VISU_IS_UI_STIPPLE_COMBOBOX(stippleComboBox), (guint16)0);
519 
520   validIter = gtk_combo_box_get_active_iter(GTK_COMBO_BOX(stippleComboBox), &iter);
521   if (!validIter)
522     return (guint16)0;
523 
524   klass = G_OBJECT_GET_CLASS(stippleComboBox);
525   gtk_tree_model_get(GTK_TREE_MODEL(VISU_UI_STIPPLE_COMBOBOX_CLASS(klass)->listStoredStipples), &iter,
526 		     COLUMN_STIPPLE_VALUE, &stipple,
527 		     -1);
528   return (guint16)stipple;
529 }
530 /**
531  * visu_ui_stipple_combobox_getStamp:
532  * @stippleComboBox: a #VisuUiStippleCombobox widget ;
533  * @stipple: a pattern value.
534  *
535  * The @stippleComboBox has little pixbufs to represent the stipple. User methods can
536  * use these pixbufs but should considered them read-only.
537  *
538  * Returns: (transfer none): a pixbuf pointer corresponding to the
539  * little image shown on the @stippleComboBox.
540  *
541  * Since: 3.4
542  */
visu_ui_stipple_combobox_getStamp(VisuUiStippleCombobox * stippleComboBox,guint16 stipple)543 GdkPixbuf* visu_ui_stipple_combobox_getStamp(VisuUiStippleCombobox *stippleComboBox, guint16 stipple)
544 {
545   GtkTreeIter iter;
546   gboolean validIter;
547   GdkPixbuf *pixbuf;
548   guint cl;
549   GtkListStore *model;
550 
551   g_return_val_if_fail(VISU_IS_UI_STIPPLE_COMBOBOX(stippleComboBox) && stipple, (GdkPixbuf*)0);
552 
553   model = VISU_UI_STIPPLE_COMBOBOX_CLASS(G_OBJECT_GET_CLASS(stippleComboBox))->listStoredStipples;
554   validIter = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter);
555   while (validIter)
556     {
557       pixbuf = (GdkPixbuf*)0;
558       gtk_tree_model_get(GTK_TREE_MODEL(model), &iter,
559 			 COLUMN_STIPPLE_PIXBUF, &pixbuf,
560 			 COLUMN_STIPPLE_VALUE, &cl,
561 			 -1);
562       if (stipple == (guint16)cl)
563 	return pixbuf;
564       validIter = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter);
565     }
566   return (GdkPixbuf*)0;
567 }
568 /**
569  * visu_ui_stipple_combobox_add:
570  * @stippleComboBox: a #VisuUiStippleCombobox widget ;
571  * @stipple: a pattern value.
572  *
573  * Create an entry in the ComboBox for the given @stipple pattern if
574  * it does not already exist.
575  *
576  * Since: 3.4
577  */
visu_ui_stipple_combobox_add(VisuUiStippleCombobox * stippleComboBox,guint16 stipple)578 void visu_ui_stipple_combobox_add(VisuUiStippleCombobox *stippleComboBox, guint16 stipple)
579 {
580   GtkTreeIter iter;
581   gboolean validIter;
582   GObjectClass *klass;
583   GtkListStore *model;
584   guint tmpStipple;
585 
586   g_return_if_fail(VISU_IS_UI_STIPPLE_COMBOBOX(stippleComboBox));
587 
588   /* We test if the stipple already exist or not. */
589   klass = G_OBJECT_GET_CLASS(stippleComboBox);
590   model = GTK_LIST_STORE(VISU_UI_STIPPLE_COMBOBOX_CLASS(klass)->listStoredStipples);
591   validIter = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter);
592   while (validIter)
593     {
594       gtk_tree_model_get(GTK_TREE_MODEL(model), &iter,
595 			 COLUMN_STIPPLE_VALUE, &tmpStipple,
596 			 -1);
597       if ((guint16)(tmpStipple) == stipple)
598 	return ;
599       validIter = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter);
600     }
601   addStippleToModel(&iter, VISU_UI_STIPPLE_COMBOBOX_CLASS(klass), stipple);
602 }
603 /**
604  * visu_ui_stipple_combobox_set:
605  * @stippleComboBox: a #VisuUiStippleCombobox object.
606  * @stipple: a stipple value.
607  *
608  * Select the given stipple, if not exists in the model, add it. See
609  * visu_ui_stipple_combobox_setSelection() for a set method that do
610  * not add.
611  *
612  * Since: 3.8
613  **/
visu_ui_stipple_combobox_set(VisuUiStippleCombobox * stippleComboBox,guint16 stipple)614 void visu_ui_stipple_combobox_set(VisuUiStippleCombobox *stippleComboBox, guint16 stipple)
615 {
616   if (!visu_ui_stipple_combobox_setSelection(stippleComboBox, stipple))
617     {
618       visu_ui_stipple_combobox_add(stippleComboBox, stipple);
619       visu_ui_stipple_combobox_setSelection(stippleComboBox, stipple);
620     }
621 }
622