Hello la team gtk

En fouillant sur le net je suis tombé sur un code qui fait une expérience pour contraindre des widgets dans un autre. Comme c'était du gtk2, je me suis dit que cela pourrait être intéressant de le migrer à Gtk3 d'autant plus que c'est de la customisation de widget.

Bon le plus gros du job est fait. Mais il reste encore quelques points car le fonctionnement n'est pas abouti.

Voici mes fichiers, header
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef __GTK_FORM_H__
#define __GTK_FORM_H__
 
 
#include <gtk/gtk.h>
//gtk_form.h
G_BEGIN_DECLS
 
#define CB_TEST
 
G_DECLARE_FINAL_TYPE(GtkForm, gtk_form,GTK , FORM , GtkContainer)
/** signification des paramètres
 * le préfixe GtkForm pour la classe GtkFormClass
 * gtk_form pour définir le type gtk_form_get_type()
 * le transtypage GTK_FORM
 * l'ancêtre GtkContainer
 **/
 
typedef struct _GtkFormChild	  GtkFormChild;
typedef struct _GtkFormConstraint GtkFormConstraint;
 
typedef enum
{
  GTK_FORM_ATTACH_NONE,
  GTK_FORM_ATTACH_FORM,
  GTK_FORM_ATTACH_WIDGET,
  GTK_FORM_ATTACH_OPPOSITE_WIDGET,
  GTK_FORM_ATTACH_CENTER,
  GTK_FORM_ATTACH_SELF
} GtkFormAttachment;
 
typedef enum
{
/* N O T E:  These numbers ARE NOT ARBITRARY!! */
  GTK_FORM_EDGE_TOP = 0,
  GTK_FORM_EDGE_LEFT = 1,
  GTK_FORM_EDGE_BOTTOM = 2,
  GTK_FORM_EDGE_RIGHT = 3
} GtkFormEdge;
 
 
/* Type definition */
typedef struct _GtkFormPrivate GtkFormPrivate;
 
struct _GtkForm
{
  GtkContainer parent;
 
  GList *children;
  /*< Private >*/
   GtkFormPrivate *priv;
};
 
struct _GtkFormClass
{
  GtkContainerClass parent_class;
};
 
struct _GtkFormConstraint
{
  gint location;
  gint attachment;
  gint offset;
  gint factor;
  gint state;
  gboolean lower_container_relative;
  GtkFormChild *child;
  gfloat fraction;
};
 
struct _GtkFormChild
{
  GtkWidget *widget;
  GtkFormConstraint constraints [4];
};
 
/* Public API */
GtkWidget* gtk_form_new	      	      ();
void	   gtk_form_constrain	      (GtkForm	        *form,
				       GtkWidget        *child,
				       GtkFormEdge	 edge,
				       GtkFormAttachment attachment,
				       GtkWidget        *widget,
				       gint	 	 offset);
 
G_END_DECLS
#endif /* __GTK_FORM_H__ */
le code source

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
#include "gtkform.h"
#include <setjmp.h>
#include <stdio.h>
 
const gint HEIGHT = 400;
const gint WIDTH = 200;
 
enum
{
  STATE_RESET,
  STATE_VISITED,
  STATE_DONE
};
 
enum
{
  CHILD_PROP_TOP_ATTACHMENT = 1,
  CHILD_PROP_TOP_WIDGET,
  CHILD_PROP_TOP_OFFSET,
  CHILD_PROP_LEFT_ATTACHMENT,
  CHILD_PROP_LEFT_WIDGET,
  CHILD_PROP_LEFT_OFFSET,
  CHILD_PROP_BOTTOM_ATTACHMENT,
  CHILD_PROP_BOTTOM_WIDGET,
  CHILD_PROP_BOTTOM_OFFSET,
  CHILD_PROP_RIGHT_ATTACHMENT,
  CHILD_PROP_RIGHT_WIDGET,
  CHILD_PROP_RIGHT_OFFSET,
};
 
/* Private data structure */
struct _GtkFormPrivate 
{    
   gint back_color;
   gint normal_liquid_color;
   gint alert_liquid_color;
   gint trait_color;
   gint air_color;
   gint width;
   gint threshold_low;
   float jauge;
 
   GdkWindow *window;
};
 
static void gtk_form_class_init    (GtkFormClass  *klass);
static void gtk_form_init	    (GtkForm	    *form);
static void gtk_form_finalize	    (GObject	    *object);
static void gtk_form_size_request  (GtkWidget	    *widget,
				     GtkRequisition *requisition);
static void gtk_form_size_allocate (GtkWidget	    *widget,
				     GtkAllocation  *allocation);
static void gtk_form_add	    (GtkContainer   *container,
				     GtkWidget	    *widget);
static void gtk_form_remove	    (GtkContainer   *container,
				     GtkWidget	    *widget);
static void gtk_form_forall	    (GtkContainer   *container,
				     gboolean	     include_internals,
				     GtkCallback     callback,
				     gpointer	     callback_data);
static void gtk_form_set_child_property (GtkContainer   *container,
				     GtkWidget      *child,
				     guint           property_id,
				     const GValue   *value,
				     GParamSpec     *pspec);
static void gtk_form_get_child_property (GtkContainer   *container,
				     GtkWidget      *child,
				     guint           property_id,
				     GValue         *value,
				     GParamSpec     *pspec);
static GType gtk_form_child_type (GtkContainer   *container);
 
 
static void gtk_form_layout	   (GtkForm	   *form,
				    gint	   *my_bounds,
				    gboolean	    recompute_our_size);
static void gtk_form_layout_child  (jmp_buf	    env,
				    GtkFormChild   *fc,
				    gint           *my_bounds,
				    gboolean	    recompute_our_size);
static gint gtk_form_layout_edge   (jmp_buf         env,
				    GtkFormChild   *fc,
				    gint            edge,
				    gint           *my_bounds,
				    gboolean        recompute_our_size);
static void gtk_form_move_edge     (jmp_buf         env,
                                    GtkFormChild   *fc,
				    int             edge,
				    int             where,
				    gint           *my_bounds,
				    gboolean        recompute);
static gboolean gtk_form_edge_should_move_too (GtkFormChild *fc,
						gint edge);
 
static void gtk_form_get_preferred_height (GtkWidget *widget, gint *minimal_height, gint *natural_height);
static void gtk_form_get_preferred_width (GtkWidget *widget, gint *minimal_width, gint *natural_width);
static void gtk_form_realize(GtkWidget *widget);
 
static GtkContainerClass *parent_class = NULL;
 
 
/* define la variable GTK_TYPE_FORM contient la fonction  de type Gtype de la class */
#define GTK_TYPE_FORM gtk_form_get_type()
 
/* Define type */
G_DEFINE_TYPE(GtkForm, gtk_form, GTK_TYPE_CONTAINER)
/** signification des paramètres pour G_DEFINE_TYPE(GtkForm, gtk_form, GTK_TYPE_CONTAINER)
 * GtkForm est le type
 * le même préfixe GtkForm que pour la classe GtkFormClass
 * gtk_form sert l'implementation de la fonction (gtk_form)_get_type 
 * GTK_TYPE_WIDGET est le Gtype du widget parent define a parent class pointer accessible from the whole .c file
 **/
 
static GType gtk_form_attachment_get_type(void)
{
  static GType etype = 0;
  if (etype == 0) {
    static const GEnumValue values[] = {
      { GTK_FORM_ATTACH_NONE, "GTK_FORM_ATTACH_NONE", "none" },
      { GTK_FORM_ATTACH_FORM, "GTK_FORM_ATTACH_FORM", "form" },
      { GTK_FORM_ATTACH_WIDGET, "GTK_FORM_ATTACH_WIDGET", "widget" },
      { GTK_FORM_ATTACH_OPPOSITE_WIDGET, "GTK_FORM_ATTACH_OPPOSITE_WIDGET", "opposite_widget" },
      { GTK_FORM_ATTACH_CENTER, "GTK_FORM_ATTACH_CENTER", "center" },
	  { GTK_FORM_ATTACH_SELF, "GTK_FORM_ATTACH_SELF", "self" },
      { 0, NULL, NULL }
    };
	etype = g_enum_register_static ("GtkFormAttachment", values);
  }
  return etype;
}
#define GTK_TYPE_FORM_ATTACHMENT (gtk_form_attachment_get_type())
 
static void gtk_form_class_init (GtkFormClass *klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS (klass);
	GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
	GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
 
	parent_class = g_type_class_peek_parent (klass);
 
	object_class->finalize = gtk_form_finalize;
 
	widget_class->size_allocate = gtk_form_size_allocate;
 
	widget_class->get_preferred_width = gtk_form_get_preferred_width;
	widget_class->get_preferred_height = gtk_form_get_preferred_height; 
 
	widget_class->realize = gtk_form_realize;
 
	container_class->add = gtk_form_add;
	container_class->remove = gtk_form_remove;
	container_class->forall = gtk_form_forall;
	container_class->child_type = gtk_form_child_type;
 
	container_class->set_child_property = gtk_form_set_child_property;
	container_class->get_child_property = gtk_form_get_child_property;
 
  gtk_container_class_install_child_property (container_class,
  						CHILD_PROP_TOP_ATTACHMENT,
						g_param_spec_enum ("top_attachment",
							"Top attachment",
							"Type of attachment of top edge of child",
							GTK_TYPE_FORM_ATTACHMENT, GTK_FORM_ATTACH_NONE,
							G_PARAM_READWRITE));
  gtk_container_class_install_child_property (container_class,
  						CHILD_PROP_TOP_WIDGET,
						g_param_spec_object ("top_widget",
							"Top widget",
							"Target widget for top edge of child",
							GTK_TYPE_WIDGET,
							G_PARAM_READWRITE));
  gtk_container_class_install_child_property (container_class,
  						CHILD_PROP_TOP_OFFSET,
						g_param_spec_uint ("top_offset",
							"Top offset",
							"Offset from the target or form side",
							0, G_MAXUINT, 0,
							G_PARAM_READWRITE));
 
  gtk_container_class_install_child_property (container_class,
  						CHILD_PROP_LEFT_ATTACHMENT,
						g_param_spec_enum ("left_attachment",
							"Left attachment",
							"Type of attachment of left edge of child",
							GTK_TYPE_FORM_ATTACHMENT, GTK_FORM_ATTACH_NONE,
							G_PARAM_READWRITE));
  gtk_container_class_install_child_property (container_class,
  						CHILD_PROP_LEFT_WIDGET,
						g_param_spec_object ("left_widget",
							"Left widget",
							"Target widget for left edge of child",
							GTK_TYPE_WIDGET,
							G_PARAM_READWRITE));
  gtk_container_class_install_child_property (container_class,
  						CHILD_PROP_LEFT_OFFSET,
						g_param_spec_uint ("left_offset",
							"Left offset",
							"Offset from the target or form side",
							0, G_MAXUINT, 0,
							G_PARAM_READWRITE));
 
  gtk_container_class_install_child_property (container_class,
  						CHILD_PROP_BOTTOM_ATTACHMENT,
						g_param_spec_enum ("bottom_attachment",
							"Bottom attachment",
							"Type of attachment of bottom edge of child",
							GTK_TYPE_FORM_ATTACHMENT, GTK_FORM_ATTACH_NONE,
							G_PARAM_READWRITE));
  gtk_container_class_install_child_property (container_class,
  						CHILD_PROP_BOTTOM_WIDGET,
						g_param_spec_object ("bottom_widget",
							"Bottom widget",
							"Target widget for bottom edge of child",
							GTK_TYPE_WIDGET,
							G_PARAM_READWRITE));
  gtk_container_class_install_child_property (container_class,
  						CHILD_PROP_BOTTOM_OFFSET,
						g_param_spec_uint ("bottom_offset",
							"Bottom offset",
							"Offset from the target or form side",
							0, G_MAXUINT, 0,
							G_PARAM_READWRITE));
 
  gtk_container_class_install_child_property (container_class,
  						CHILD_PROP_RIGHT_ATTACHMENT,
						g_param_spec_enum ("right_attachment",
							"Right attachment",
							"Type of attachment of right edge of child",
							GTK_TYPE_FORM_ATTACHMENT, GTK_FORM_ATTACH_NONE,
							G_PARAM_READWRITE));
  gtk_container_class_install_child_property (container_class,
  						CHILD_PROP_RIGHT_WIDGET,
						g_param_spec_object ("right_widget",
							"Right widget",
							"Target widget for right edge of child",
							GTK_TYPE_WIDGET,
							G_PARAM_READWRITE));
  gtk_container_class_install_child_property (container_class,
  						CHILD_PROP_RIGHT_OFFSET,
						g_param_spec_uint ("right_offset",
							"Right offset",
							"Offset from the target or form side",
							0, G_MAXUINT, 0,
							G_PARAM_READWRITE));
}
 
static GType gtk_form_child_type (GtkContainer   *container)
{
  return GTK_TYPE_WIDGET;
}
 
static GtkFormChild *gtk_form_find_child (GtkForm *form, GtkWidget *widget)
{
	GList *list;
	for (list = form->children; list; list = list->next)
	{
		GtkFormChild *form_child = list->data;
		if (form_child->widget == widget)
			return form_child;
	}
	return NULL;
}
 
static void gtk_form_set_child_property (GtkContainer      *container,
			GtkWidget    *child,
			guint         property_id,
			const GValue *value,
			GParamSpec   *pspec)
{
  GtkForm *form = GTK_FORM(container);
  GtkFormChild *form_child;
 
  form_child = gtk_form_find_child (form, child);
  if (!form_child) {
	GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
    return;
  }
 
  switch (property_id) {
  case CHILD_PROP_TOP_ATTACHMENT:
    form_child->constraints [GTK_FORM_EDGE_TOP].attachment = g_value_get_enum(value);
	break;
  case CHILD_PROP_TOP_WIDGET:
    form_child->constraints [GTK_FORM_EDGE_TOP].child = gtk_form_find_child (form, GTK_WIDGET (g_value_get_object (value)));
	break;
  case CHILD_PROP_TOP_OFFSET:
    form_child->constraints [GTK_FORM_EDGE_TOP].offset = g_value_get_uint(value);
	break;
  case CHILD_PROP_LEFT_ATTACHMENT:
    form_child->constraints [GTK_FORM_EDGE_LEFT].attachment = g_value_get_enum(value);
	break;
  case CHILD_PROP_LEFT_WIDGET:
    form_child->constraints [GTK_FORM_EDGE_LEFT].child = gtk_form_find_child (form, GTK_WIDGET (g_value_get_object (value)));
	break;
  case CHILD_PROP_LEFT_OFFSET:
    form_child->constraints [GTK_FORM_EDGE_LEFT].offset = g_value_get_uint(value);
	break;
  case CHILD_PROP_BOTTOM_ATTACHMENT:
    form_child->constraints [GTK_FORM_EDGE_BOTTOM].attachment = g_value_get_enum(value);
	break;
  case CHILD_PROP_BOTTOM_WIDGET:
    form_child->constraints [GTK_FORM_EDGE_BOTTOM].child = gtk_form_find_child (form, GTK_WIDGET (g_value_get_object (value)));
	break;
  case CHILD_PROP_BOTTOM_OFFSET:
    form_child->constraints [GTK_FORM_EDGE_BOTTOM].offset = g_value_get_uint(value);
	break;
  case CHILD_PROP_RIGHT_ATTACHMENT:
    form_child->constraints [GTK_FORM_EDGE_RIGHT].attachment = g_value_get_enum(value);
	break;
  case CHILD_PROP_RIGHT_WIDGET:
    form_child->constraints [GTK_FORM_EDGE_RIGHT].child = gtk_form_find_child (form, GTK_WIDGET (g_value_get_object (value)));
	break;
  case CHILD_PROP_RIGHT_OFFSET:
    form_child->constraints [GTK_FORM_EDGE_RIGHT].offset = g_value_get_uint(value);
	break;
  default:
    GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
    break;
  }
}
 
static void gtk_form_get_child_property (GtkContainer      *container,
			GtkWidget    *child,
			guint         property_id,
			GValue       *value,
			GParamSpec   *pspec)
{
  GtkForm *form = GTK_FORM(container);
  GtkFormChild *form_child = gtk_form_find_child (form, child);
 
  if (!form_child) {
	GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
    return;
  }
 
  switch (property_id) {
  case CHILD_PROP_TOP_ATTACHMENT:
    g_value_set_enum (value, form_child->constraints[GTK_FORM_EDGE_TOP].attachment);
	break;
  case CHILD_PROP_TOP_WIDGET:
    g_value_set_object (value,
		form_child->constraints[GTK_FORM_EDGE_TOP].child ?
		G_OBJECT(form_child->constraints[GTK_FORM_EDGE_TOP].child) : NULL);
    break;
  case CHILD_PROP_TOP_OFFSET:
    g_value_set_uint(value, form_child->constraints[GTK_FORM_EDGE_TOP].offset);
	break;
  case CHILD_PROP_LEFT_ATTACHMENT:
    g_value_set_enum (value, form_child->constraints[GTK_FORM_EDGE_LEFT].attachment);
	break;
  case CHILD_PROP_LEFT_WIDGET:
    g_value_set_object (value,
		form_child->constraints[GTK_FORM_EDGE_LEFT].child ?
		G_OBJECT(form_child->constraints[GTK_FORM_EDGE_LEFT].child) : NULL);
    break;
  case CHILD_PROP_LEFT_OFFSET:
    g_value_set_uint(value, form_child->constraints[GTK_FORM_EDGE_LEFT].offset);
	break;
  case CHILD_PROP_BOTTOM_ATTACHMENT:
    g_value_set_enum (value, form_child->constraints[GTK_FORM_EDGE_BOTTOM].attachment);
	break;
  case CHILD_PROP_BOTTOM_WIDGET:
    g_value_set_object (value,
		form_child->constraints[GTK_FORM_EDGE_BOTTOM].child ?
		G_OBJECT(form_child->constraints[GTK_FORM_EDGE_BOTTOM].child) : NULL);
    break;
  case CHILD_PROP_BOTTOM_OFFSET:
    g_value_set_uint(value, form_child->constraints[GTK_FORM_EDGE_BOTTOM].offset);
	break;
  case CHILD_PROP_RIGHT_ATTACHMENT:
    g_value_set_enum (value, form_child->constraints[GTK_FORM_EDGE_RIGHT].attachment);
	break;
  case CHILD_PROP_RIGHT_WIDGET:
    g_value_set_object (value,
		form_child->constraints[GTK_FORM_EDGE_RIGHT].child ?
		G_OBJECT(form_child->constraints[GTK_FORM_EDGE_RIGHT].child) : NULL);
    break;
  case CHILD_PROP_RIGHT_OFFSET:
    g_value_set_uint(value, form_child->constraints[GTK_FORM_EDGE_RIGHT].offset);
	break;
  default:
    GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
    break;
  }
}
 
static void gtk_form_init (GtkForm *form)
{
	#ifdef CB_TEST
		g_print ("gtk_form_init\n");
	#endif
	GtkFormPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE(form, GTK_TYPE_FORM, GtkFormPrivate);
 
	gtk_widget_set_has_window(GTK_WIDGET(form), TRUE);
 
 
	form->priv = priv;
 
 
	gtk_widget_set_has_window(GTK_WIDGET(form), FALSE);
	gtk_widget_set_redraw_on_allocate (GTK_WIDGET (form), FALSE);
 
	form->children = NULL;
}
 
GtkWidget* gtk_form_new ()
{
	#ifdef CB_TEST
		g_print ("instance gtk_form_new créé\n");
	#endif
	return GTK_WIDGET (g_object_new (GTK_TYPE_FORM, NULL));
}
 
void gtk_form_constrain (GtkForm	     *form,
		    GtkWidget	     *child,
		    GtkFormEdge       edge,
		    GtkFormAttachment attachment,
		    GtkWidget        *widget,
		    gint              offset)
{
	GtkFormChild *form_child;
 
	g_return_if_fail (form != NULL);
	g_return_if_fail (GTK_IS_FORM (form));
	g_return_if_fail (child != NULL);
	g_return_if_fail (GTK_IS_WIDGET (child));
 
	form_child = gtk_form_find_child (form, child);
	if (!form_child)
	return;
	#ifdef CB_TEST
		g_print ("gtk_form_constrain en action \n");
	#endif
 
	form_child->constraints[edge].location = 0;
	form_child->constraints[edge].attachment = attachment;
	form_child->constraints[edge].offset = offset;
	form_child->constraints[edge].child = gtk_form_find_child (form, widget);
 
	// pourquoi un child (ex un button ) aurait-il automatiquement un parent ?
	//if (gtk_widget_get_visible (child->parent) /* && GTK_WIDGET_VISIBLE (child) */ )
	//{
		//if (gtk_widget_get_mapped (child->parent))
			//gtk_widget_map (child);
 
		//gtk_widget_queue_resize (child);
	//}
	gtk_widget_map (child);
	gtk_widget_queue_resize (child);
}
 
static void gtk_form_finalize (GObject *object)
{
	g_return_if_fail (object != NULL);
	g_return_if_fail (GTK_IS_FORM (object));
 
	//GtkForm *form = GTK_FORM (object);
 
	G_OBJECT_CLASS (parent_class)->finalize (object);
	//G_OBJECT_CLASS (parent_class)->finalize (form);
}
 
static void gtk_form_size_request(GtkWidget *widget, GtkRequisition *requisition) 
{
	/** nous stockons la taille préférée de notre widget, cette fonction ne sert qu'a cela
         * mais requisition sera par la suite consulté **/
	g_return_if_fail (widget != NULL);
	g_return_if_fail (GTK_FORM (widget));
	g_return_if_fail (requisition != NULL);
	#ifdef CB_TEST
		g_print ("gtk_form_size_request\n");
	#endif	
	requisition->width  = WIDTH;
	requisition->height = HEIGHT;
}
 
static void gtk_form_get_preferred_width (GtkWidget *widget, gint *minimal_width, gint *natural_width)
{
	/** la fonction établit une largeur   xxxxx   **/
	g_return_if_fail (widget != NULL);
	#ifdef CB_TEST
		g_print ("gtk_form_get_preferred_width\n");
	#endif
	GtkRequisition requisition;
	GList *children;
	GtkForm *form = GTK_FORM (widget);
	gint my_bounds [4] = { 0, 0, 0, 0 };
 
	gtk_form_size_request (widget, &requisition);
	*minimal_width = *natural_width = requisition.width;
	for (children = form->children; children; children = children->next)
	{
		GtkRequisition minimum_size;
        GtkRequisition natural_size; // non utilisé ?
		GtkFormChild *child = children->data;
 
		gtk_widget_get_preferred_size (child->widget, &minimum_size, &natural_size);
 
		child->constraints [GTK_FORM_EDGE_RIGHT].location =
		child->constraints [GTK_FORM_EDGE_LEFT].location +
		minimum_size.width - 1;
	}
 
	gtk_form_layout (form, my_bounds, 1);
 
	requisition.width = my_bounds [GTK_FORM_EDGE_RIGHT] + 1;
	requisition.width += gtk_container_get_border_width(GTK_CONTAINER (form)) * 2;
 
	for (children = form->children; children; children = children->next)
	{
		GtkFormChild *child = children->data;
 
		child->constraints [GTK_FORM_EDGE_LEFT].fraction =
		(float)child->constraints [GTK_FORM_EDGE_LEFT].location / 
		(float)(my_bounds [GTK_FORM_EDGE_RIGHT]);
 
		child->constraints [GTK_FORM_EDGE_RIGHT].fraction =
		(float)child->constraints [GTK_FORM_EDGE_RIGHT].location / 
		(float)(my_bounds [GTK_FORM_EDGE_RIGHT]);
 
		child->constraints [GTK_FORM_EDGE_TOP].fraction =
		(float)child->constraints [GTK_FORM_EDGE_TOP].location / 
		(float)(my_bounds [GTK_FORM_EDGE_BOTTOM]);
 
		child->constraints [GTK_FORM_EDGE_BOTTOM].fraction =
		(float)child->constraints [GTK_FORM_EDGE_BOTTOM].location / 
		(float)(my_bounds [GTK_FORM_EDGE_BOTTOM]);
	}
}
 
static void gtk_form_get_preferred_height (GtkWidget *widget, gint *minimal_height, gint *natural_height)
{
	/** la fonction établit une hauteur   xxxxx   **/
	g_return_if_fail (widget != NULL);
	#ifdef CB_TEST
		g_print ("gtk_form_get_preferred_height\n");
	#endif
	GtkRequisition requisition;
	GList *children;
	GtkForm *form = GTK_FORM (widget);
	gint my_bounds [4] = { 0, 0, 0, 0 };
 
	gtk_form_size_request (widget, &requisition);
	*minimal_height = *natural_height = requisition.height;
	for (children = form->children; children; children = children->next)
	{
		GtkRequisition minimum_size;
        GtkRequisition natural_size; // non utilisé ?
		GtkFormChild *child = children->data;
 
		gtk_widget_get_preferred_size (child->widget, &minimum_size, &natural_size);
 
		child->constraints [GTK_FORM_EDGE_BOTTOM].location =
		child->constraints [GTK_FORM_EDGE_TOP].location +
		minimum_size.height - 1;
	}
 
	gtk_form_layout (form, my_bounds, 1);
 
	requisition.height = my_bounds [GTK_FORM_EDGE_BOTTOM] + 1;
	requisition.height += gtk_container_get_border_width(GTK_CONTAINER (form)) * 2;
 
	for (children = form->children; children; children = children->next)
	{
		GtkFormChild *child = children->data;
 
		child->constraints [GTK_FORM_EDGE_LEFT].fraction =
		(float)child->constraints [GTK_FORM_EDGE_LEFT].location / 
		(float)(my_bounds [GTK_FORM_EDGE_RIGHT]);
 
		child->constraints [GTK_FORM_EDGE_RIGHT].fraction =
		(float)child->constraints [GTK_FORM_EDGE_RIGHT].location / 
		(float)(my_bounds [GTK_FORM_EDGE_RIGHT]);
 
		child->constraints [GTK_FORM_EDGE_TOP].fraction =
		(float)child->constraints [GTK_FORM_EDGE_TOP].location / 
		(float)(my_bounds [GTK_FORM_EDGE_BOTTOM]);
 
		child->constraints [GTK_FORM_EDGE_BOTTOM].fraction =
		(float)child->constraints [GTK_FORM_EDGE_BOTTOM].location / 
		(float)(my_bounds [GTK_FORM_EDGE_BOTTOM]);
	}
}
 
static void gtk_form_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
{
	GtkForm *form;
	GList *children;
	gint my_bounds [4];
 
	g_return_if_fail (widget != NULL);
	g_return_if_fail (GTK_IS_FORM (widget));
	g_return_if_fail (allocation != NULL);
 
	#ifdef CB_TEST
		g_print ("gtk_form_size_allocate en action \n");
	#endif
	gtk_widget_set_allocation(widget, allocation);
	form = GTK_FORM (widget);
	g_print(" gtk_form_size_allocate passe ici %d\n", __LINE__); 
 
	my_bounds [GTK_FORM_EDGE_TOP] = 0 ;
	my_bounds [GTK_FORM_EDGE_LEFT] = 0 ;
	my_bounds [GTK_FORM_EDGE_BOTTOM] = my_bounds [GTK_FORM_EDGE_TOP] +
					 allocation->height - 1 - 2*gtk_container_get_border_width(GTK_CONTAINER (form));
	my_bounds [GTK_FORM_EDGE_RIGHT] = my_bounds [GTK_FORM_EDGE_LEFT] +
					allocation->width - 1 - 2*gtk_container_get_border_width(GTK_CONTAINER (form));
 
	gtk_form_layout (form, my_bounds, 0);
 
	GtkAllocation allocation_form;
 
	gtk_widget_get_allocation(GTK_WIDGET (form),&allocation_form);
 
	g_print(" gtk_form_size_allocate passe ici %d\n", __LINE__);
 
	for (children = form->children; children; children = children->next)
	{
		GtkFormChild *child = children->data;
		GtkAllocation allocation;
 
 
		g_print(" gtk_form_size_allocate passe ici %d\n", __LINE__);
 
		allocation.x = child->constraints [GTK_FORM_EDGE_LEFT].location +
				allocation_form.x + gtk_container_get_border_width(GTK_CONTAINER (form));
 
		g_print(" gtk_form_size_allocate passe ici %d\n", __LINE__);
 
		allocation.y = child->constraints [GTK_FORM_EDGE_TOP].location +
				allocation_form.y + gtk_container_get_border_width(GTK_CONTAINER (form));
 
		g_print(" gtk_form_size_allocate passe ici %d\n", __LINE__);
 
		allocation.width = child->constraints [GTK_FORM_EDGE_RIGHT].location -
				 child->constraints [GTK_FORM_EDGE_LEFT].location + 1;
		allocation.height = child->constraints [GTK_FORM_EDGE_BOTTOM].location -
				  child->constraints [GTK_FORM_EDGE_TOP].location + 1;
 
		gtk_widget_size_allocate (child->widget, &allocation);
	}
}
 
static void gtk_form_add (GtkContainer *container, GtkWidget    *widget)
{
  GtkForm *form;
  GtkFormChild *form_child;
  gint i;
 
  g_return_if_fail (container != NULL);
  g_return_if_fail (GTK_IS_FORM (container));
  g_return_if_fail (widget != NULL);
  // ? g_return_if_fail (widget->parent == NULL);
  #ifdef CB_TEST
		g_print ("gtk_form_add en action \n");
	#endif
  form = GTK_FORM (container);
 
  form_child = g_new (GtkFormChild, 1);
  form_child->widget = widget;
 
  for (i = 0; i < 4; i ++)
  {
    form_child->constraints[i].location = 0;
    form_child->constraints[i].attachment = GTK_FORM_ATTACH_NONE;
    form_child->constraints[i].offset = 0;
    form_child->constraints[i].factor = i < 2 ? 1 : -1;
    form_child->constraints[i].state = STATE_RESET;
    form_child->constraints[i].child = NULL;
    form_child->constraints[i].lower_container_relative = FALSE;
    form_child->constraints[i].fraction = 1.0;
  }
 
  form->children = g_list_prepend (form->children, form_child);
 
  gtk_widget_set_parent (widget, GTK_WIDGET (form));
}
 
static void gtk_form_remove (GtkContainer *container,
		  GtkWidget    *widget)
{
  GtkForm *form;
  GtkFormChild *child;
  GList *children;
 
  g_return_if_fail (container != NULL);
  g_return_if_fail (GTK_IS_FORM (container));
  g_return_if_fail (widget != NULL);
 
  form = GTK_FORM (container);
  children = form->children;
 
  while (children)
    {
      child = children->data;
      children = children->next;
 
      if (child->widget == widget)
	{
	  gtk_widget_unparent (widget);
 
	  form->children = g_list_remove (form->children, child);
	  g_free (child);
 
	  if (gtk_widget_get_visible (GTK_WIDGET (container)))
	    gtk_widget_queue_resize (GTK_WIDGET (container));
	  break;
	}
    }
}
 
static void gtk_form_forall (GtkContainer *container,
		  gboolean	include_internals,
		  GtkCallback	callback,
		  gpointer	callback_data)
{
  GtkForm *form;
  GtkFormChild *child;
  GList *children;
 
  g_return_if_fail (container != NULL);
  g_return_if_fail (GTK_IS_FORM (container));
  g_return_if_fail (callback != NULL);
 
  form = GTK_FORM (container);
  children = form->children;
 
  while (children)
    {
      child = children->data;
      children = children->next;
 
      (* callback) (child->widget, callback_data);
    }
}
 
static void gtk_form_layout (GtkForm *form, gint *my_bounds, gboolean recompute_our_size)
{
    int count;
    for (count = 0; count < 10000; )
    {
        GList *list;
	gboolean it_worked = 1;
 
	/** Reset the state of all edges. **/
 
	for (list = form->children; list; list = list->next)
	{
	    int edge;
	    GtkFormChild *form_child = list->data;
 
	    for (edge = 0; edge < 4; edge ++)
	        form_child->constraints [edge].state = STATE_RESET;
	}
 
	for (list = form->children; list; list = list->next)
	{
	    GtkFormChild *form_child = list->data;
 
	    jmp_buf env;
 
	    if (setjmp (env) == 0)
		gtk_form_layout_child (env, form_child, my_bounds,
				       recompute_our_size);
	    else
	    {
		it_worked = 0;
		count ++;
		break;
	    }
	}
 
	if (it_worked)
	    break;
    }
}
 
static void gtk_form_layout_child (jmp_buf env, GtkFormChild *fc, gint *my_bounds,
		       gboolean recompute_our_size)
{
    gint edge;
    for (edge = 0; edge < 4; edge ++)
	gtk_form_layout_edge (env, fc, edge, my_bounds, recompute_our_size);
}
 
static gint gtk_form_layout_edge (jmp_buf env, GtkFormChild *fc, gint edge,
		      gint *my_bounds, gboolean recompute_our_size)
{
    GtkFormConstraint *ec = &fc->constraints [edge];
 
    if (ec->state != STATE_DONE)
    {
	if (ec->state == STATE_VISITED)
	    printf ("FormLayout.layout: Circular dependency!\n");
	else
	{
	    gint location = 0;
 
	    ec->state = STATE_VISITED;
 
	    /*
	     * At this point, we can do the work.
	     */
 
	    switch (ec->attachment)
	    {
		case GTK_FORM_ATTACH_SELF:
			if ( !recompute_our_size ) {
				location = (int)(my_bounds [edge] * ec->fraction);
				break ;
			}
			/* if computing size fall through to NONE */
 
		case GTK_FORM_ATTACH_NONE:
			location = ec->location;
			ec->offset = 0;
 
			/*
			 * Edges that don't have attachmenta are now
			 * treated as if they were attached relative to the
			 * opposite edge.  This lets us propagate the value
			 * for lower_container_relative.  Since it is possible
			 * that the opposite edge depends on this edge, we
			 * need to catch the circular dependency first.
			 */
 
			if ( fc->constraints[edge^2].state != STATE_VISITED ) {
				gtk_form_layout_edge(env, fc, edge^2, my_bounds,
									recompute_our_size);
				location = ec->location ;
			}
			ec->lower_container_relative = 
				fc->constraints[edge^2].lower_container_relative;
		    break;
 
		case GTK_FORM_ATTACH_FORM:
		    location = my_bounds [edge];
			ec->lower_container_relative =
					edge == GTK_FORM_EDGE_BOTTOM ||
					edge == GTK_FORM_EDGE_RIGHT ;
		    break;
 
		case GTK_FORM_ATTACH_WIDGET:
		    location = ec->factor +	/* This IS correct */
			       gtk_form_layout_edge (env, ec->child,
						     edge ^ 2, my_bounds,
						     recompute_our_size);
			ec->lower_container_relative =
				fc->constraints[edge^2].lower_container_relative;
		    break;
 
		case GTK_FORM_ATTACH_OPPOSITE_WIDGET:
		    location = gtk_form_layout_edge (env, ec->child,
						     edge, my_bounds,
						     recompute_our_size);
			ec->lower_container_relative =
				fc->constraints[edge].lower_container_relative;
		    break;
 
		case GTK_FORM_ATTACH_CENTER:
		{
		    gint center;
		    gint size;
 
		    if (ec->child == NULL)	/* Center on form */
		    {
			center = (my_bounds [edge ^ 2] -
				  my_bounds [edge]) / 2;
			if (center < 0) center = -center;
		    }
		    else
		    {
		        gint edge1;
		        gint edge2;
		        gint half;
 
			gtk_form_layout_edge (env, ec->child,
					      edge ^ 2, my_bounds,
					      recompute_our_size);
 			gtk_form_layout_edge (env, ec->child,
					      edge, my_bounds,
					      recompute_our_size);
 
			/* It might be tempting to use the return of
			 * gtk_form_layout_edge rather than the next 2 lines
			 * of code.  Bad idea because the second call to
			 * gtk_form_layout_edge may move the first edge.
			 */
 
			edge1 = ec->child->constraints [edge^2].location;
			edge2 = ec->child->constraints [edge].location;
			half = (edge1 - edge2) / 2;
			center = ec->child->constraints [edge].location +
				 half;
		    }
 
		    /* We depend on the opposite edge so lets lay him out
		     * first.
			 */
 
		    gtk_form_layout_edge (env, fc, edge ^ 2, my_bounds,
					    recompute_our_size);
 
		    size = fc->constraints [edge ^ 2].location -
			       fc->constraints [edge].location + 1;
 
		    location = center - size / 2;
 
		    break;
		}
 
		default:
		    printf ("FormLayout: Unknown attachment type!\n");
	    }
 
	    location += ec->offset * ec->factor;
 
	    gtk_form_move_edge (env, fc, edge, location, my_bounds,
				recompute_our_size && ec->lower_container_relative);
 
	    ec->state = STATE_DONE;
	}
    }
 
    return fc->constraints [edge].location;
}
 
static void gtk_form_move_edge (jmp_buf env, GtkFormChild *fc, int edge, int where,
		    gint *my_bounds, gboolean recompute)
{
    int diff = where - fc->constraints [edge].location;
 
    int opposite_edge = edge ^ 2;
 
    if (gtk_form_edge_should_move_too (fc, opposite_edge))
	fc->constraints [opposite_edge].location += diff;
    else
    {
	/* Special Case:  If we are in "recompute" mode and we shrink
	 * because of this constraint, then we need to expand the form
	 * to accomodate us instead of shrinking the child.
	 */
 
	if (recompute)
	{
	    int delta = diff * fc->constraints [opposite_edge].factor;
 
	    if (delta < 0)
	    {
		if (edge == GTK_FORM_EDGE_TOP || edge == GTK_FORM_EDGE_BOTTOM)
		    my_bounds [GTK_FORM_EDGE_BOTTOM] += -delta;
		else
		    my_bounds [GTK_FORM_EDGE_RIGHT] += -delta;
 
		longjmp (env, 1);
	    }
	}
    }
 
    fc->constraints [edge].location += diff;
}
 
static gboolean gtk_form_edge_should_move_too (GtkFormChild *fc, gint edge)
{
    /* Should edge move if the opposite edge moves.  e.g. If the LEFT
     * edge moves 10 pixels, should the RIGHT edge move too?
	 *
     * Simply stated, an edge can move if there are no constraints for
     * that edge or the constraints for that edge are relative to itself
     * (specifies a width) or the edge has not been layed out yet.
	 */
 
    int attachment = fc->constraints [edge].attachment;
 
    return (attachment == GTK_FORM_ATTACH_NONE) ||
	   (fc->constraints [edge].state != STATE_DONE) ||
	   (attachment == GTK_FORM_ATTACH_WIDGET &&
	    fc->constraints [edge].child == fc);
}
 
static void gtk_form_realize(GtkWidget *widget) 
{
	/** cette fonction est au coeur du dispositif c'est ici que la fenêtre est créé
         * avec les bonnes dimensions
         * notamment  la couche de dessin est préparé avec le contexte cairo
         * et le format de dessin classique
         **/
	g_return_if_fail (widget != NULL);
	g_return_if_fail (GTK_FORM (widget));
	#ifdef CB_TEST
		g_print ("gtkform_realize\n");
	#endif
	GtkFormPrivate *priv = GTK_FORM(widget)->priv;
	GtkAllocation allocation;
	GdkWindowAttr attrs;
	guint attrs_mask;
 
	gtk_widget_set_realized(widget, TRUE);
 
	gtk_widget_get_allocation(widget, &allocation);
 
	attrs.x           = allocation.x;
	attrs.y           = allocation.y;
	attrs.width       = allocation.width;
	attrs.height      = allocation.height;
	attrs.window_type = GDK_WINDOW_CHILD;
	attrs.wclass      = GDK_INPUT_OUTPUT;
	attrs.event_mask  = gtk_widget_get_events(widget) | GDK_EXPOSURE_MASK;
 
	attrs_mask = GDK_WA_X | GDK_WA_Y;
 
	priv->window = gdk_window_new(gtk_widget_get_parent_window(widget),
			   &attrs, attrs_mask);
	gdk_window_set_user_data(priv->window, widget);
	gtk_widget_set_window(widget, priv->window);
 
	/**widget->style = gtk_style_attach(gtk_widget_get_style( widget ),
                                                         priv->window);
        //gtk_style_set_background(widget->style, priv->window, GTK_STATE_NORMAL);**/
	GtkStyleContext * context = gtk_style_context_new ();
 
	cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 500,500);
	cairo_t *cairo = cairo_create (surface);
	gtk_render_background (context,
                       cairo,
                       allocation.x,
                       allocation.y,
                       allocation.width,
                       allocation.height);  
}
et pour finir le code de test form.c
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
 
#include <gtk/gtk.h>
#include "gtkform.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
 
/* Our callback.
 * The data passed to this function is printed to stdout */
void callback( GtkWidget *widget,
               gpointer   data )
{
    g_print ("Hello again - %s was pressed\n", (char *) data);
}
 
/* This callback quits the program */
gint delete_event( GtkWidget *widget,
                   GdkEvent  *event,
                   gpointer   data )
{
    gtk_main_quit ();
    return FALSE;
}
 
int main( int   argc,
          char *argv[] )
{
    GtkWidget *window;
    GtkWidget *button1;
    GtkWidget *button2;
    GtkWidget *button3;
    GtkWidget *button4;
    GtkWidget *quit;
    GtkWidget *form;
	int c ;
	guint width = 0 ;
	guint fwidth = 0 ;
	gboolean self = FALSE ;
 
    gtk_init (&argc, &argv);
 
	while ( (c=getopt(argc, argv, "b:B:s")) != EOF ) {
		switch (c) {
		case 'b' :
			fwidth = atoi(optarg) ;
			break ;
		case 'B' :
			width = atoi(optarg) ;
			break ;
		case 's' :
			self = TRUE ;
			break ;
		default :
			fprintf(stderr, "usage: form [-b n] [-B n] [-s]\n") ;
			fprintf(stderr, "   -b n    border width of form\n") ;
			fprintf(stderr, "   -B n    border width of window\n") ;
			fprintf(stderr, "   -s      make self attachments\n") ;
			return 1 ;
		}
	}
 
    /* Create a new window */
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 
    /* Set the window title */
    gtk_window_set_title (GTK_WINDOW (window), "Table");
 
    /* Set a handler for delete_event that immediately
     * exits GTK. */
    g_signal_connect (G_OBJECT (window), "delete_event",
                      G_CALLBACK (delete_event), NULL);
 
    /* Sets the border width of the window. */
    gtk_container_set_border_width (GTK_CONTAINER (window), width);
 
    /* Create a form */
    form = gtk_form_new ();
 
    /* Put the form in the main window */
    gtk_container_add (GTK_CONTAINER (window), form);
    gtk_container_set_border_width (GTK_CONTAINER (form), fwidth);
 
    /* Create first button */
    button1 = gtk_button_new_with_label ("button 1");
 
    /* When the button is clicked, we call the "callback" function
     * with a pointer to "button 1" as its argument */
    g_signal_connect (G_OBJECT (button1), "clicked",
	              G_CALLBACK (callback), (gpointer) "button 1");
 
 
    /* Insert button 1 into the upper left quadrant of the form */
	gtk_container_add(GTK_CONTAINER(form), button1);
    gtk_form_constrain (GTK_FORM (form), button1, GTK_FORM_EDGE_TOP, GTK_FORM_ATTACH_FORM, NULL, 0);
    gtk_form_constrain (GTK_FORM (form), button1, GTK_FORM_EDGE_LEFT, GTK_FORM_ATTACH_FORM, NULL, 0);
	if ( self ) {
	  gtk_form_constrain (GTK_FORM (form), button1, GTK_FORM_EDGE_RIGHT, GTK_FORM_ATTACH_SELF, NULL, 0);
	  gtk_form_constrain (GTK_FORM (form), button1, GTK_FORM_EDGE_BOTTOM, GTK_FORM_ATTACH_SELF, NULL, 0);
	}
 
    gtk_widget_show (button1);
 
    /* Create second button */
 
    button2 = gtk_button_new_with_label ("button 2");
 
    /* When the button is clicked, we call the "callback" function
     * with a pointer to "button 2" as its argument */
    g_signal_connect (G_OBJECT (button2), "clicked",
                      G_CALLBACK (callback), (gpointer) "button 2");
 
    /* Insert button 2 into the upper right quadrant of the form */
	gtk_container_add(GTK_CONTAINER(form), button2);
    gtk_form_constrain (GTK_FORM (form), button2, GTK_FORM_EDGE_TOP, GTK_FORM_ATTACH_FORM, NULL, 0);
    gtk_form_constrain (GTK_FORM (form), button2, GTK_FORM_EDGE_LEFT, GTK_FORM_ATTACH_WIDGET, button1, 0);
	if ( self ) {
	  gtk_form_constrain (GTK_FORM (form), button2, GTK_FORM_EDGE_RIGHT, GTK_FORM_ATTACH_SELF, NULL, 0);
	  gtk_form_constrain (GTK_FORM (form), button2, GTK_FORM_EDGE_BOTTOM, GTK_FORM_ATTACH_SELF, NULL, 0);
	}
 
    gtk_widget_show (button2);
 
    /* Create third button */
 
    button3 = gtk_button_new_with_label ("button 3");
 
    /* When the button is clicked, we call the "callback" function
     * with a pointer to "button 2" as its argument */
    g_signal_connect (G_OBJECT (button3), "clicked",
                      G_CALLBACK (callback), (gpointer) "button 3");
 
    /* Insert button 3 into the upper right quadrant of the form */
	gtk_container_add(GTK_CONTAINER(form), button3);
    gtk_form_constrain (GTK_FORM (form), button3, GTK_FORM_EDGE_TOP, GTK_FORM_ATTACH_FORM, NULL, 0);
    gtk_form_constrain (GTK_FORM (form), button3, GTK_FORM_EDGE_LEFT, GTK_FORM_ATTACH_WIDGET, button2, 0);
	if ( self ) {
	  gtk_form_constrain (GTK_FORM (form), button3, GTK_FORM_EDGE_RIGHT, GTK_FORM_ATTACH_SELF, NULL, 0);
	  gtk_form_constrain (GTK_FORM (form), button3, GTK_FORM_EDGE_BOTTOM, GTK_FORM_ATTACH_SELF, NULL, 0);
	}
 
    gtk_widget_show (button3);
 
    /* Create fourth button */
 
    button4 = gtk_button_new_with_label ("button 4");
 
    /* When the button is clicked, we call the "callback" function
     * with a pointer to "button 2" as its argument */
    g_signal_connect (G_OBJECT (button4), "clicked",
                      G_CALLBACK (callback), (gpointer) "button 4");
 
    /* Insert button 4 into the upper right quadrant of the form */
	gtk_container_add(GTK_CONTAINER(form), button4);
    gtk_form_constrain (GTK_FORM (form), button4, GTK_FORM_EDGE_TOP, GTK_FORM_ATTACH_FORM, NULL, 0);
    gtk_form_constrain (GTK_FORM (form), button4, GTK_FORM_EDGE_LEFT, GTK_FORM_ATTACH_WIDGET, button3, 0);
    gtk_form_constrain (GTK_FORM (form), button4, GTK_FORM_EDGE_RIGHT, GTK_FORM_ATTACH_FORM, NULL, 0);
	if ( self ) {
	  gtk_form_constrain (GTK_FORM (form), button4, GTK_FORM_EDGE_BOTTOM, GTK_FORM_ATTACH_SELF, NULL, 0);
	}
 
    gtk_widget_show (button4);
 
    /* Create "Quit" button */
    quit = gtk_button_new_with_label ("Quit");
 
    /* When the button is clicked, we call the "delete_event" function
     * and the program exits */
    g_signal_connect (G_OBJECT (quit), "clicked",
                      G_CALLBACK (delete_event), NULL);
 
    /* Insert the quit button into the
     * lower half of the form */
 
	gtk_container_add(GTK_CONTAINER(form), quit);
    gtk_form_constrain (GTK_FORM (form), quit, GTK_FORM_EDGE_TOP, GTK_FORM_ATTACH_WIDGET, button1, 0);
    gtk_form_constrain (GTK_FORM (form), quit, GTK_FORM_EDGE_LEFT, GTK_FORM_ATTACH_FORM, NULL, 0);
    gtk_form_constrain (GTK_FORM (form), quit, GTK_FORM_EDGE_RIGHT, GTK_FORM_ATTACH_FORM, NULL, 0);
    gtk_form_constrain (GTK_FORM (form), quit, GTK_FORM_EDGE_BOTTOM, GTK_FORM_ATTACH_FORM, NULL, 0);
 
    gtk_widget_show (quit);
    gtk_widget_show (form);
    gtk_widget_show (window);
 
    gtk_main ();
 
    return 0;
}
et le fichier mesonbuild

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
project('mygtkform', 'c')
gtkdep = dependency('gtk+-3.0')
cc = meson.get_compiler('c')
math_dep = cc.find_library('m', required : false)
scr= [ 'gtkform.c','form.c','gtkform.h']
executable('form', scr, dependencies : [math_dep,gtkdep])
les symptômes : une fois compilé, à l’exécution l'affichage apparaît de temps en temps et il y a beaucoup d'erreur d’exécution. Le traçage m'oriente à minima vers des coquilles dans gtk_form_constrain...

Avez-vous une idée de ce qui manque pour terminer l'affaire SVP?

Merci d'avance pour vos éclairages