IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

GTK+ avec C & C++ Discussion :

gtkform et contrainte


Sujet :

GTK+ avec C & C++

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    147
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 147
    Points : 88
    Points
    88
    Par défaut gtkform et contrainte
    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

  2. #2
    Expert confirmé
    Avatar de gerald3d
    Homme Profil pro
    Conducteur de train
    Inscrit en
    Février 2008
    Messages
    2 291
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Conducteur de train
    Secteur : Transports

    Informations forums :
    Inscription : Février 2008
    Messages : 2 291
    Points : 4 941
    Points
    4 941
    Billets dans le blog
    5
    Par défaut
    Bonjour turboiii.

    Comme j'ai du temps, comme tu peux l'imaginer, je me plonge corps et âme dans ton problème .

    Après une première lecture, je vois que tu utilises G_DEFINE_TYPE() pour définir ton objet. Pourquoi pas ? Cependant tu as aussi une structure private pour cet objet. Il conviendrait mieux alors d'utiliser G_DEFINE_TYPE_WITH_PRIVATE(). Ainsi le pointeur interne priv sera directement initialisé.
    Pour pouvoir utiliser tout ce petit monde correctement il faut que toutes les déclarations des structures soient faites dans le header.
    Dernière remarque. Puisque il y a une structure privée la liste children doit en faire partie.
    Voici le header modifié :
    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
    #ifndef __GTK_FORM_H__
    #define __GTK_FORM_H__
    
    #include <gtk/gtk.h>
    
    G_BEGIN_DECLS
    
    #define CB_TEST
    
    /* define la variable GTK_TYPE_FORM contient la fonction  de type Gtype de la class */
    #define GTK_TYPE_FORM gtk_form_get_type ()
    
    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;
    
      /*< Private >*/
      GtkFormPrivate *priv;
    };
    
    /* Private data structure */
    struct _GtkFormPrivate 
    {
      GList *children;
      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;
    };
    
    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__ */
    Bien entendu ces modifications vont avoir une incidence importante sur le code source.

    Tout d'abord nous définissons le type privé. Pas grand chose à dire de plus ici :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    G_DEFINE_TYPE_WITH_PRIVATE(GtkForm, gtk_form, GTK_TYPE_CONTAINER)
    Dans gtk_form_init (); nous allons utiliser gtk_form_get_instance_private(); en lieu et place de G_TYPE_INSTANCE_GET_PRIVATE() qui est obsolète.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    static void gtk_form_init (GtkForm *form)
    {
    #ifdef CB_TEST
      g_print ("gtk_form_init\n");
    #endif
     
      GtkFormPrivate *priv = gtk_form_get_instance_private (form);
      priv->children = NULL;
      ...
    }
    Comme tu peux le voir j'initialise ici children puisqu'elle fait partie de la structure privée maintenant.
    Dans la foulée il faut ici initialiser toutes les données de la structure privée. Ce qui pourrait donner :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
      priv->children            = NULL;
      priv->back_color          = 0;
      priv->normal_liquid_color = 0;
      priv->alert_liquid_color  = 0;
      priv->trait_color         = 0;
      priv->air_color           = 0;
      priv->width               = 0;
      priv->threshold_low       = 0;
      priv->jauge               = 0;
      priv->window              = NULL;
    Je n'ai pas encore regardé à quoi servent toutes ces données. Je suis donc parti du principe de les initialiser en fonction de leur type.

    Avant de clôturer ce premier post une dernière remarque qui vaut pour toutes les fonctions internes à l'objet.
    Prenons pour exemple cette fonction :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    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;
    }
    Il faut tester tous les paramètres en entrée. Ce que tu fais ici. Mais ce n'est pas le cas pour toutes. A faire donc. Je vais pousser un peu la forme des tests.
    Tester si widget est NULL puis ensuite tester ce même widget s'il est de type GtkForm n'est pas très optimisé. Le fait de tester si widget est de type GtkForm est largement suffisant puisque si widget est NULL il n'est pas de type GtkForm non plus. Tu peux donc supprimer le premier test.

    Dernier exemple sur cette fonction :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    static void gtk_form_layout (GtkForm *form, gint *my_bounds, gboolean recompute_our_size)
    {
        int count;
        for (count = 0; count < 10000; )
        {
            GList *list;
        ...
    Ici il n'y a aucun test !

    Je te laisse prendre ce que tu veux dans toutes ses remarques.

    P.S. :

    Histoire d'enfoncer le clou une dernière fonction pour te montrer les modifications nécessaires après tout ce que j'ai écrit :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    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;
    }
    Cette fonction prendra la forme suivante pour accéder à la liste children et pour tester ses paramètres :
    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
    static GtkFormChild *gtk_form_find_child (GtkForm *form, GtkWidget *widget)
    {
      g_return_val_if_fail (GTK_IS_FORM (form), NULL);
      if (!widget) return;  /* Ce n'est pas une erreur si widget est NULL. Donc pas de warning en console */
      g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); /* Si widget n'est pas un GtkWidget alors c'est une erreur */
      GtkFormPrivate *priv = gtk_form_get_instance_private (form);
     
      GList *list = priv->children;
      GtkFormChild *form_child;
      while (list) {
        form_child = list->data;
        if (form_child->widget == widget)
          return form_child;
        list = g_list_next (list);
      }
     
      return NULL;
    }
    Bon codage.

    Gérald

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    147
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 147
    Points : 88
    Points
    88
    Par défaut
    hello

    Ok merci Gérald pour ta réponse très riche. Ce code hérite des défauts émis par le concepteur initial sans oublier les bourdes de j'ai rajouté ou bien mes oublis. Je vais étudier toutes tes remarques. Merci encore

  4. #4
    Expert confirmé
    Avatar de gerald3d
    Homme Profil pro
    Conducteur de train
    Inscrit en
    Février 2008
    Messages
    2 291
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Conducteur de train
    Secteur : Transports

    Informations forums :
    Inscription : Février 2008
    Messages : 2 291
    Points : 4 941
    Points
    4 941
    Billets dans le blog
    5
    Par défaut
    J'ai quelques peu modifié le code source depuis pour obtenir quelque chose d'utilisable. Il est encore perfectible mais il est stable et fonctionnel.
    Je ne le poste pas pour le moment te laissant le loisir de creuser de ton côté.

    Voila ce que j'obtiens graphiquement :
    Nom : Capture d’écran_2020-03-28_09-22-25.png
Affichages : 189
Taille : 12,6 Ko

    Tous les widgets sont bien entendu fonctionnels.

  5. #5
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    147
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 147
    Points : 88
    Points
    88
    Par défaut
    hello Gerald

    je vois que que tu as réussi à en faire quelque chose de ce machin. Effectivement je suis en train de faire la mise à niveau. mais c'est pas encore au point

  6. #6
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    147
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 147
    Points : 88
    Points
    88
    Par défaut
    suite

    dans le fichier de test j'ai remplacé les multiples gtk_widget_show(foo); par une commande unique et bien plus efficace gtk_widget_show_all(window);

    d'autre part voici mon code source en l'état

    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
    1031
    1032
    1033
    1034
    1035
    1036
    1037
    1038
    1039
    1040
    1041
    1042
    1043
    1044
    1045
    1046
    1047
    1048
    1049
    1050
    1051
    1052
    1053
    1054
    1055
    1056
    1057
    1058
    1059
    1060
    1061
    1062
    1063
    1064
    1065
    1066
    1067
    #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,
    };
     
     
    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 private type */
    G_DEFINE_TYPE_WITH_PRIVATE(GtkForm, gtk_form, GTK_TYPE_CONTAINER)
    /** signification des paramètres pour G_DEFINE_TYPE_WITH_PRIVATE(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)
    {
    	/** ici on va détecter la présence d'un widget enfant dans la liste du container form **/
     
    	if (widget == NULL)
    		g_print (" Warning ici widget est NULL pourquoi ?\n");
    	else
    		g_print (" Warning ici widget est consistant\n");
    	g_return_val_if_fail (GTK_IS_FORM (form), NULL);
    	g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
    	GtkFormPrivate *priv = gtk_form_get_instance_private (form);
     
    	GList *list = priv->children;
    	GtkFormChild *form_child;
    	while (list)
    	{
    		form_child = list->data;
    		if (form_child->widget == widget)
    			return form_child;
    		list = g_list_next (list);
    	}
    	// pas de chance pas trouvé !!!
    	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 = gtk_form_find_child (form, child);
     
    	if (!form_child)
    	{
    		g_print (" Warning ici form_child est NULL pourquoi ?\n");
    		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 = gtk_form_get_instance_private (form);
     
    	form->priv = priv;
    	priv->children            = NULL;
    	priv->back_color          = 0;
    	priv->normal_liquid_color = 0;
    	priv->alert_liquid_color  = 0;
    	priv->trait_color         = 0;
    	priv->air_color           = 0;
    	priv->width               = 0;
    	priv->threshold_low       = 0;
    	priv->jauge               = 0;
    	priv->window              = NULL;
     
    	//gtk_widget_set_has_window(GTK_WIDGET(form), TRUE);
    	gtk_widget_set_has_window(GTK_WIDGET(form), TRUE);
    	//gtk_widget_set_redraw_on_allocate (GTK_WIDGET (form), FALSE);
    	gtk_widget_set_redraw_on_allocate (GTK_WIDGET (form), TRUE);
    }
     
    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)
    {
    	/** je suppose ici que une fois gtk_container_add(GTK_CONTAINER(form), widget);
             * a rajouté un widget dans la liste, cette commande permet d'appliquer la contrainte
             * il faut donc le trouver et le traiter
             * transfo utilisation de la structure privée nécessaire **/
    	GtkFormChild *form_child;
     
    	g_return_if_fail (GTK_IS_FORM (form));
    	g_return_if_fail (GTK_IS_WIDGET (child));
     
    	// c'est ici qu'on le cherche
    	form_child = gtk_form_find_child (form, child);
    	if (!form_child)
    	return;
    	// arrivé ici on l'a sous le coude et on applique les contraintes
    	#ifdef CB_TEST
    		g_print ("gtk_form_constrain en action widget trouvé\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);
    	//}
     
     
    	// je teste l'application des contraintes sur le widget traité via la structure privé???
    	if ( gtk_widget_get_visible (form_child->widget))
    		if (gtk_widget_get_mapped (form_child->widget))
    			gtk_widget_map (form_child->widget);
    	gtk_widget_queue_resize (child);
     
    }
     
    static void gtk_form_finalize (GObject *object)
    {
    	g_return_if_fail (GTK_IS_FORM (object));
    	#ifdef CB_TEST
    		g_print ("gtk_form_finalize\n");
    	#endif
    	GtkFormPrivate *priv = gtk_form_get_instance_private (GTK_FORM (object));
    	// a voir si je dois libérer des ressources au moins la Glist?
     
    	g_free (priv->children);
     
      /* Always chain up to the parent class; as with dispose(), finalize()
       * is guaranteed to exist on the parent's class virtual function table
       */
     
    	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 (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 (GTK_FORM (widget));
    	#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 (GTK_FORM (widget));
    	#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 (GTK_FORM (widget));
    	//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)
    {
    	/** pour moi c'est ici que la commande gtk_container_add(GTK_CONTAINER(form), widget);
             * va entrer en action par subtitution/complément de gtk_container_add
             * notamment rajouter l'enfant à la liste privée
             **/
     
    	g_return_if_fail (GTK_IS_FORM (container));
    	g_return_if_fail (widget != NULL);
    	/** je comprend avec la commande si dessous que si le wiget a déjà un parent
             * cela va être difficile de le sortir de l'autre structure pour le coller va générer un conflit
             **/
    	//g_return_if_fail (widget->parent == NULL);
    	// nouvelle commande plus adpter au contexte en gtk3 ????
    	// g_return_if_fail (gtk_widget_get_parent_window(widget)); est-ce utile à ce stade du dev ???
    	#ifdef CB_TEST
    		g_print ("gtk_form_add en action \n");
    	#endif
    	gint i;
     
    	GtkForm * form = GTK_FORM (container);
    	GtkFormPrivate *priv = gtk_form_get_instance_private (form);
     
    	//création et remplissage de la structure form_child
    	GtkFormChild *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;
    	}
    	priv->children = g_list_prepend (priv->children, form_child);
    	// tient c'est ici qu'on définit que l'enfant à un parent et c'est le container bon ok!!
    	/** gtk_widget_set_parent (GtkWidget *widget,
                           GtkWidget *parent);
         * This function is useful only when implementing subclasses of GtkContainer.
         * Sets the container as the parent of widget , and takes care of some details
         * such as updating the state and style of the child to reflect its new location
         **/
    	gtk_widget_set_parent (widget, GTK_WIDGET (form));
    }
     
    static void gtk_form_remove (GtkContainer *container, GtkWidget    *widget)
    {
    	/** je suppose ici qu'il faut retirer un widget du container initial
             * transfo utilisation de la structure privée nécessaire **/
    	g_return_if_fail (GTK_IS_FORM (container));
    	g_return_if_fail (GTK_FORM (widget));
     
    	GtkFormChild *child;
    	GList *children;
    	GtkForm *form = GTK_FORM (container);
     
    	GtkFormPrivate *priv = gtk_form_get_instance_private (form);
    	children = priv->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)
    {
      GtkFormChild *child;
      GList *children;
     
      g_return_if_fail (GTK_IS_FORM (container));
      g_return_if_fail (callback != NULL);
     
      GtkForm *form = GTK_FORM (container);
      GtkFormPrivate *priv = gtk_form_get_instance_private (form);
      children = priv->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;
        g_return_if_fail (GTK_FORM (form));
        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 (GTK_FORM (widget));
    	#ifdef CB_TEST
    		g_print ("gtkform_realize\n");
    	#endif
     
    	GtkForm *form = GTK_FORM (widget);
    	GtkFormPrivate *priv = gtk_form_get_instance_private (form);
     
    	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);  
    }
    clairement j'ai une fenêtre vide encore.
    si tu pouvais me mettre sur la voie sans donner la solution ... car c'est mieux d'apprendre soi même que de copier bêtement
    déjà je comprends mieux l'usage de structure privée ...

  7. #7
    Expert confirmé
    Avatar de gerald3d
    Homme Profil pro
    Conducteur de train
    Inscrit en
    Février 2008
    Messages
    2 291
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Conducteur de train
    Secteur : Transports

    Informations forums :
    Inscription : Février 2008
    Messages : 2 291
    Points : 4 941
    Points
    4 941
    Billets dans le blog
    5
    Par défaut
    Citation Envoyé par turboiii Voir le message
    suite

    dans le fichier de test j'ai remplacé les multiples gtk_widget_show(foo); par une commande unique et bien plus efficace gtk_widget_show_all(window);
    Oui tu as raison. Les gtk_window_show (); successifs ne servent à rien. Pour ma part j'ai pas mal factorisé le code de main (); :
    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
       /* 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);
     
        /* Creation of 4 identical buttons */
        gint i;
        gchar *label;
        GtkWidget *button;
        GtkWidget *oldbutton = NULL;
        for (i=0; i < 4; i++) {
          label = g_strdup_printf ("button %d", i+1);
          button = gtk_button_new_with_label (label);
          gtk_widget_set_name (button, label);
          g_free (label);
     
          /* When the button is clicked, we call the "callback" function */
          g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (callback), NULL);
     
          /* Insert button into the upper left quadrant of the form */
          gtk_container_add(GTK_CONTAINER(form), button);
          gtk_form_constrain (GTK_FORM (form), button, GTK_FORM_EDGE_TOP, GTK_FORM_ATTACH_FORM, NULL, 0);
     
          switch (i) {
          case 0:
    	gtk_form_constrain (GTK_FORM (form), button, GTK_FORM_EDGE_LEFT, GTK_FORM_ATTACH_FORM, NULL, 0);
    	break;
          case 1:
          case 2:
    	gtk_form_constrain (GTK_FORM (form), button, GTK_FORM_EDGE_LEFT, GTK_FORM_ATTACH_WIDGET, oldbutton, 0);
    	break;
          case 3:
    	gtk_form_constrain (GTK_FORM (form), button, GTK_FORM_EDGE_LEFT, GTK_FORM_ATTACH_WIDGET, oldbutton, 0);
    	gtk_form_constrain (GTK_FORM (form), button, GTK_FORM_EDGE_RIGHT, GTK_FORM_ATTACH_FORM, NULL, 0);
    	gtk_form_constrain (GTK_FORM (form), button, GTK_FORM_EDGE_BOTTOM, GTK_FORM_ATTACH_SELF, NULL, 0);
    	break;
          }
          if ( self && i!= 3) {
    	gtk_form_constrain (GTK_FORM (form), button, GTK_FORM_EDGE_RIGHT, GTK_FORM_ATTACH_SELF, NULL, 0);
    	gtk_form_constrain (GTK_FORM (form), button, GTK_FORM_EDGE_BOTTOM, GTK_FORM_ATTACH_SELF, NULL, 0);
          }
          oldbutton=button;
        }
     
        /* 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, button, 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_all (window);
    Au passage je ne transmets plus le texte du bouton à la fonction callback. Je récupère directement son nom que j'ai au préalable initialisé.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    void callback( GtkWidget *widget,
                   gpointer   data )
    {
      g_print ("Hello again - %s was pressed\n", gtk_widget_get_name (widget));
    }
    Pour revenir à ton dernier code à la première compilation j'obtiens ceci :
    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
    gtkform.c: Dans la fonction «*gtk_form_get_preferred_width*»:
    gtkform.c:510:22: erreur: «*GtkForm*» {alias «*struct _GtkForm*»} n'a pas de membre nommé «*children*»
      510 |  for (children = form->children; children; children = children->next)
          |                      ^~
    gtkform.c:528:22: erreur: «*GtkForm*» {alias «*struct _GtkForm*»} n'a pas de membre nommé «*children*»
      528 |  for (children = form->children; children; children = children->next)
          |                      ^~
    gtkform.c: Dans la fonction «*gtk_form_get_preferred_height*»:
    gtkform.c:564:22: erreur: «*GtkForm*» {alias «*struct _GtkForm*»} n'a pas de membre nommé «*children*»
      564 |  for (children = form->children; children; children = children->next)
          |                      ^~
    gtkform.c:582:22: erreur: «*GtkForm*» {alias «*struct _GtkForm*»} n'a pas de membre nommé «*children*»
      582 |  for (children = form->children; children; children = children->next)
          |                      ^~
    gtkform.c: Dans la fonction «*gtk_form_size_allocate*»:
    gtkform.c:636:22: erreur: «*GtkForm*» {alias «*struct _GtkForm*»} n'a pas de membre nommé «*children*»
      636 |  for (children = form->children; children; children = children->next)
          |                      ^~
    gtkform.c: Dans la fonction «*gtk_form_remove*»:
    gtkform.c:736:9: erreur: «*GtkForm*» {alias «*struct _GtkForm*»} n'a pas de membre nommé «*children*»
      736 |     form->children = g_list_remove (form->children, child);
          |         ^~
    gtkform.c:736:41: erreur: «*GtkForm*» {alias «*struct _GtkForm*»} n'a pas de membre nommé «*children*»
      736 |     form->children = g_list_remove (form->children, child);
          |                                         ^~
    gtkform.c: Dans la fonction «*gtk_form_layout*»:
    gtkform.c:781:18: erreur: «*GtkForm*» {alias «*struct _GtkForm*»} n'a pas de membre nommé «*children*»
      781 |  for (list = form->children; list; list = list->next)
          |                  ^~
    gtkform.c:790:18: erreur: «*GtkForm*» {alias «*struct _GtkForm*»} n'a pas de membre nommé «*children*»
      790 |  for (list = form->children; list; list = list->next)
    Cela vient sûrement du fait que tu n'utilises pas le header que je t'ai transmis plus haut. Pour ma part children est déclaré dans GtkFormPrivate et n'est plus déclaré dans GtkForm.

    J'ai rectifié toutes les erreurs pour pouvoir compiler. Le code s'exécute avec pas mal de warnings en console mais tous les widgets sont présents. Leur interaction avec la souris par contre est inopérante.

    Voici les warnings importants en console :
    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
    Warning ici widget est consistant
     Warning ici widget est NULL pourquoi ?
     
    ** (test:19699): CRITICAL **: 14:19:08.406: gtk_form_find_child: assertion 'GTK_IS_WIDGET (widget)' failed
     Warning ici widget est consistant
     Warning ici widget est NULL pourquoi ?
     
    ** (test:19699): CRITICAL **: 14:19:08.406: gtk_form_find_child: assertion 'GTK_IS_WIDGET (widget)' failed
     Warning ici widget est consistant
     Warning ici widget est NULL pourquoi ?
     
    ** (test:19699): CRITICAL **: 14:19:08.407: gtk_form_find_child: assertion 'GTK_IS_WIDGET (widget)' failed
     Warning ici widget est consistant
     Warning ici widget est consistant
     Warning ici widget est consistant
     Warning ici widget est NULL pourquoi ?
     
    ** (test:19699): CRITICAL **: 14:19:08.407: gtk_form_find_child: assertion 'GTK_IS_WIDGET (widget)' failed
     Warning ici widget est consistant
     Warning ici widget est consistant
     Warning ici widget est consistant
     Warning ici widget est NULL pourquoi ?
     
    ** (test:19699): CRITICAL **: 14:19:08.407: gtk_form_find_child: assertion 'GTK_IS_WIDGET (widget)' failed
     Warning ici widget est consistant
     Warning ici widget est consistant
     Warning ici widget est consistant
     Warning ici widget est NULL pourquoi ?
     
    ** (test:19699): CRITICAL **: 14:19:08.407: gtk_form_find_child: assertion 'GTK_IS_WIDGET (widget)' failed
     Warning ici widget est consistant
     Warning ici widget est NULL pourquoi ?
     
    ** (test:19699): CRITICAL **: 14:19:08.407: gtk_form_find_child: assertion 'GTK_IS_WIDGET (widget)' failed
     Warning ici widget est consistant
     Warning ici widget est consistant
     Warning ici widget est consistant
     Warning ici widget est NULL pourquoi ?
     
    ** (test:19699): CRITICAL **: 14:19:08.407: gtk_form_find_child: assertion 'GTK_IS_WIDGET (widget)' failed
     Warning ici widget est consistant
     Warning ici widget est NULL pourquoi ?
     
    ** (test:19699): CRITICAL **: 14:19:08.407: gtk_form_find_child: assertion 'GTK_IS_WIDGET (widget)' failed
     Warning ici widget est consistant
     Warning ici widget est NULL pourquoi ?
     
    ** (test:19699): CRITICAL **: 14:19:08.407: gtk_form_find_child: assertion 'GTK_IS_WIDGET (widget)' failed
    On voit que gtk_form_find_child(); génère un warning sur le deuxième argument. Ce n'est pas forcément une erreur de transmettre NULL sur celui-ci. Il peut être intéressant d'ajouter une condition pour le tester avant de vérifier son type ici.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    static GtkFormChild *gtk_form_find_child (GtkForm *form, GtkWidget *widget)
    {
    	/** ici on va détecter la présence d'un widget enfant dans la liste du container form **/
     
    	if (widget == NULL)
    		g_print (" Warning ici widget est NULL pourquoi ?\n");
    	else
    		g_print (" Warning ici widget est consistant\n");
    	g_return_val_if_fail (GTK_IS_FORM (form), NULL);
            if (!widget) return NULL;
    	g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
    	GtkFormPrivate *priv = gtk_form_get_instance_private (form);
            ...
    Après ces quelques modifications il reste à comprendre pourquoi le signal "clicked" ne fonctionne que sur les boutons 1 et 2 chez moi. Chez toi peut-être qu'ils vont tous fonctionner puisque nous n'avons pas le même main ();...

  8. #8
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    147
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 147
    Points : 88
    Points
    88
    Par défaut
    suite j'ai fini par trouver qu'il manque à minima une fonction draw que j'ai rajouté

    mais c'est pas encore ça mais ca avance
    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
    1031
    1032
    1033
    1034
    1035
    1036
    1037
    1038
    1039
    1040
    1041
    1042
    1043
    1044
    1045
    1046
    1047
    1048
    1049
    1050
    1051
    1052
    1053
    1054
    1055
    1056
    1057
    1058
    1059
    1060
    1061
    1062
    1063
    1064
    1065
    1066
    1067
    1068
    1069
    1070
    1071
    1072
    1073
    1074
    1075
    1076
    1077
    1078
    1079
    1080
    1081
    1082
    1083
    1084
    1085
    1086
    1087
    1088
    1089
    1090
    1091
    1092
    1093
    1094
    1095
    1096
    1097
    1098
    1099
    1100
    1101
    1102
    1103
    1104
    1105
    1106
    #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,
    };
     
     
    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 gboolean gtk_form_draw (GtkWidget *draw_area, cairo_t *cairo);
     
    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 private type */
    G_DEFINE_TYPE_WITH_PRIVATE(GtkForm, gtk_form, GTK_TYPE_CONTAINER)
    /** signification des paramètres pour G_DEFINE_TYPE_WITH_PRIVATE(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;
    	widget_class->draw = gtk_form_draw;
     
    	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)
    {
    	/** ici on va détecter la présence d'un widget enfant dans la liste du container form **/
     
    	if (widget == NULL)
    		g_print (" WARNING ici widget est NULL pourquoi ? %d\n", __LINE__); 
    	else
    		g_print (" ici widget est consistant\n");
    	g_return_val_if_fail (GTK_IS_FORM (form), NULL);
    	g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
    	GtkFormPrivate *priv = gtk_form_get_instance_private (form);
     
    	GList *list = priv->children;
    	GtkFormChild *form_child;
    	while (list)
    	{
    		form_child = list->data;
    		if (form_child->widget == widget)
    			return form_child;
    		list = g_list_next (list);
    	}
    	// pas de chance pas trouvé !!!
    	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);
    	#ifdef CB_TEST
    		g_print ("trace avant appel gtk_form_find_child %d\n", __LINE__); 
    	#endif
    	GtkFormChild * form_child = gtk_form_find_child (form, child);
     
    	if (!form_child)
    	{
    		g_print (" WARNING ici form_child est NULL pourquoi %d\n", __LINE__); 
    		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);
    	#ifdef CB_TEST
    		g_print ("trace avant appel gtk_form_find_child %d\n", __LINE__); 
    	#endif
    	GtkFormChild *form_child = gtk_form_find_child (form, child);
     
    	if (!form_child)
    	{
    		g_print (" WARNING ici form_child est NULL pourquoi %d\n", __LINE__); 
    		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 = gtk_form_get_instance_private (form);
     
    	/* Set default values */
    	priv->children            = NULL;
    	priv->window              = NULL;
     
    	/* Create cache for faster access */
    	form->priv = priv;
     
    	gtk_widget_set_has_window(GTK_WIDGET(form), TRUE);
     
    	//gtk_widget_set_redraw_on_allocate (GTK_WIDGET (form), FALSE);
    	gtk_widget_set_redraw_on_allocate (GTK_WIDGET (form), TRUE);
    }
     
    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)
    {
    	/** je suppose ici que une fois gtk_container_add(GTK_CONTAINER(form), widget);
             * a rajouté un widget dans la liste, cette commande permet d'appliquer la contrainte
             * il faut donc le trouver et le traiter
             * transfo utilisation de la structure privée nécessaire **/
    	GtkFormChild *form_child;
     
    	g_return_if_fail (GTK_IS_FORM (form));
    	g_return_if_fail (GTK_IS_WIDGET (child));
     
    	#ifdef CB_TEST
    		g_print ("trace avant appel gtk_form_find_child %d\n", __LINE__); 
    	#endif
    	// c'est ici qu'on le cherche
    	form_child = gtk_form_find_child (form, child);
    	if (!form_child)
    	return;
    	// arrivé ici on l'a sous le coude et on applique les contraintes
    	#ifdef CB_TEST
    		g_print ("gtk_form_constrain en action widget trouvé \n"); 
    	#endif
     
    	form_child->constraints[edge].location = 0;
    	form_child->constraints[edge].attachment = attachment;
    	form_child->constraints[edge].offset = offset;
    	#ifdef CB_TEST
    		g_print ("trace avant appel gtk_form_find_child ici normal widget est NULL c'est la commande %d\n", __LINE__); 
    	#endif
    	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);
    	//}
     
     
    	// je teste l'application des contraintes sur le widget traité via la structure privé???
     
    	//if ( gtk_widget_get_visible (form_child->widget))
    		//if (gtk_widget_get_mapped (form_child->widget))
    			//gtk_widget_map (form_child->widget);
    	//gtk_widget_queue_resize (child);
    	// peut-être commande trop globale ??
    	if (gtk_widget_get_visible (GTK_WIDGET (form)))
    			gtk_widget_queue_resize (GTK_WIDGET (form));
    }
     
    static void gtk_form_finalize (GObject *object)
    {
    	g_return_if_fail (GTK_IS_FORM (object));
    	#ifdef CB_TEST
    		g_print ("gtk_form_finalize\n");
    	#endif
     
    	//GtkForm * form = GTK_FORM (object);
    	//GtkFormPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE(form, GTK_TYPE_FORM, GtkFormPrivate);
    	//// a voir si je dois libérer des ressources au moins la Glist?
     
    	//GList *children = priv->children;
     
    	//GtkFormChild *child;
     
    	//while (children)
        //{
    		//child = children->data;
    		//children = g_list_remove (children, child);
    		//g_free (child);	
        //}
     
      /* Always chain up to the parent class; as with dispose(), finalize()
       * is guaranteed to exist on the parent's class virtual function table
       */
     
    	G_OBJECT_CLASS (parent_class)->finalize (object);
    }
     
    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 (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 (GTK_FORM (widget));
    	#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 (GTK_FORM (widget));
    	#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)
    {
    	g_return_if_fail (GTK_FORM (widget));
    	g_return_if_fail (allocation != NULL);
    	gint my_bounds [4];
    	#ifdef CB_TEST
    		g_print(" gtk_form_size_allocate passe ici %d\n", __LINE__); 
    	#endif
    	gtk_widget_set_allocation(widget, allocation);
    	GtkForm *form = GTK_FORM (widget);
     
    	GtkFormPrivate *priv = gtk_form_get_instance_private (form);
     
    	GList *children = priv->children;
     
    	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);
     
    	for (children = form->children; children; children = children->next)
    	{
    		GtkFormChild *child = children->data;
    		GtkAllocation allocation;
     
    		allocation.x = child->constraints [GTK_FORM_EDGE_LEFT].location +
    				allocation_form.x + gtk_container_get_border_width(GTK_CONTAINER (form));
     
    		allocation.y = child->constraints [GTK_FORM_EDGE_TOP].location +
    				allocation_form.y + gtk_container_get_border_width(GTK_CONTAINER (form));
     
    		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)
    {
    	/** pour moi c'est ici que la commande gtk_container_add(GTK_CONTAINER(form), widget);
             * va entrer en action par subtitution/complément de gtk_container_add
             * notamment rajouter l'enfant à la liste privée
             **/
     
    	g_return_if_fail (GTK_IS_FORM (container));
    	g_return_if_fail (widget != NULL);
    	/** je comprend avec la commande si dessous que si le wiget a déjà un parent
             * cela va être difficile de le sortir de l'autre structure pour le coller va générer un conflit
             **/
    	//g_return_if_fail (widget->parent == NULL);
    	// nouvelle commande plus adpter au contexte en gtk3 ????
    	// g_return_if_fail (gtk_widget_get_parent_window(widget)); est-ce utile à ce stade du dev ???
    	#ifdef CB_TEST
    		g_print ("gtk_form_add en action %d\n", __LINE__); 
    	#endif
    	gint i;
     
    	GtkForm * form = GTK_FORM (container);
    	GtkFormPrivate *priv = gtk_form_get_instance_private (form);
     
    	//création et remplissage de la structure form_child
    	GtkFormChild *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;
    	}
    	priv->children = g_list_prepend (priv->children, form_child);
    	// tient c'est ici qu'on définit que l'enfant à un parent et c'est le container bon ok!!
    	/** gtk_widget_set_parent (GtkWidget *widget,
                           GtkWidget *parent);
         * This function is useful only when implementing subclasses of GtkContainer.
         * Sets the container as the parent of widget , and takes care of some details
         * such as updating the state and style of the child to reflect its new location
         **/
    	gtk_widget_set_parent (widget, GTK_WIDGET (form));
    }
     
    static void gtk_form_remove (GtkContainer *container, GtkWidget    *widget)
    {
    	/** je suppose ici qu'il faut retirer un widget du container initial
             * transfo utilisation de la structure privée nécessaire **/
    	g_return_if_fail (GTK_IS_FORM (container));
    	g_return_if_fail (GTK_FORM (widget));
     
    	GtkFormChild *child;
    	GList *children;
    	GtkForm *form = GTK_FORM (container);
     
    	GtkFormPrivate *priv = gtk_form_get_instance_private (form);
    	children = priv->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)
    {
      GtkFormChild *child;
      GList *children;
     
      g_return_if_fail (GTK_IS_FORM (container));
      g_return_if_fail (callback != NULL);
     
      GtkForm *form = GTK_FORM (container);
      GtkFormPrivate *priv = gtk_form_get_instance_private (form);
      children = priv->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;
        g_return_if_fail (GTK_FORM (form));
        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 (GTK_FORM (widget));
    	#ifdef CB_TEST
    		g_print ("gtkform_realize %d\n", __LINE__); 
    	#endif
     
    	GtkForm *form = GTK_FORM (widget);
    	GtkFormPrivate *priv = gtk_form_get_instance_private (form);
     
    	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);  
    }
     
    static gboolean gtk_form_draw (GtkWidget *drawing_area, cairo_t *cairo)
    {
     
    	g_return_val_if_fail (GTK_FORM (drawing_area),FALSE);
    	#ifdef CB_TEST
    		g_print ("gtk_form_draw\n");
    	#endif
     
    	gint width = gtk_widget_get_allocated_width (drawing_area);
    	gint height = gtk_widget_get_allocated_height (drawing_area);
     
    	//GtkSpinButtonDiscretPrivate *priv = GTK_SPINBUTTONDISCRET(widget)->priv;
    	gint center_x = (width / 2) ;
    	gint center_y = (height / 2);
     
    	/** comment on s'y prend pour dessiner les différents widgets **/
    	cairo_arc(cairo, center_x, center_y, 50, 0, 2 * 3.14);
    	cairo_stroke(cairo);
    	return TRUE;
     
     
    	/** return TRUE because we've handled this event, so no
             * further processing is required. **/
    	return TRUE;
    }

  9. #9
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    147
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 147
    Points : 88
    Points
    88
    Par défaut
    Hello la suite devait arriver....

    J'ai trouvé mon erreur grâce à ta remarque relative à l’usage de children dans la structure privée j'avais créé une belle coquille car mon code n'était pas cohérent . Maintenant tout est bien dans la structure privée

    voici mes 3 codes
    le 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
    88
    89
    90
    91
    92
    93
    94
    95
     
    #ifndef __GTK_FORM_H__
    #define __GTK_FORM_H__
     
     
    #include <gtk/gtk.h>
    //gtk_form.h
    G_BEGIN_DECLS
     
    #define CB_TEST
     
    /* define la variable GTK_TYPE_FORM contient la fonction  de type Gtype de la class */
    #define GTK_TYPE_FORM gtk_form_get_type ()
     
    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;
    /* Private data structure */
    struct _GtkFormPrivate 
    {
    	GList *children;
    	GdkWindow *window;
    };
     
    struct _GtkForm
    {
      GtkContainer parent;
      /*< 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 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
    1031
    1032
    1033
    1034
    1035
    1036
    1037
    1038
    1039
    1040
    1041
    1042
    1043
    1044
    1045
    1046
    1047
    1048
    1049
    1050
    1051
    1052
    1053
    1054
    1055
    1056
    1057
    1058
    1059
    1060
    1061
    1062
    1063
    1064
    1065
    1066
    1067
    1068
    1069
    1070
    1071
    1072
    1073
    #include "gtkform.h"
    #include <setjmp.h>
    #include <stdio.h>
     
    const gint HEIGHT = 200;
    const gint WIDTH = 300;
     
    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,
    };
     
    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 private type */
    G_DEFINE_TYPE_WITH_PRIVATE(GtkForm, gtk_form, GTK_TYPE_CONTAINER)
    /** signification des paramètres pour G_DEFINE_TYPE_WITH_PRIVATE(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)
    {
    	/** ici on va détecter la présence d'un widget enfant dans la liste du container form **/
     
    	if (widget == NULL)
    		g_print (" WARNING ici widget est NULL pourquoi ? %d\n", __LINE__); 
    	else
    		g_print (" ici widget est consistant\n");
    	g_return_val_if_fail (GTK_IS_FORM (form), NULL);
    	g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
    	GtkFormPrivate *priv = gtk_form_get_instance_private (form);
     
    	GList *list = priv->children;
    	GtkFormChild *form_child;
    	while (list)
    	{
    		form_child = list->data;
    		if (form_child->widget == widget)
    			return form_child;
    		list = g_list_next (list);
    	}
    	// pas de chance pas trouvé !!!
    	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);
    	#ifdef CB_TEST
    		g_print ("trace avant appel gtk_form_find_child %d\n", __LINE__); 
    	#endif
    	GtkFormChild * form_child = gtk_form_find_child (form, child);
     
    	if (!form_child)
    	{
    		g_print (" WARNING ici form_child est NULL pourquoi %d\n", __LINE__); 
    		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);
    	#ifdef CB_TEST
    		g_print ("trace avant appel gtk_form_find_child %d\n", __LINE__); 
    	#endif
    	GtkFormChild *form_child = gtk_form_find_child (form, child);
     
    	if (!form_child)
    	{
    		g_print (" WARNING ici form_child est NULL pourquoi %d\n", __LINE__); 
    		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 = gtk_form_get_instance_private (form);
     
    	/* Set default values */
    	priv->children            = NULL;
    	priv->window              = NULL;
     
    	/* Create cache for faster access */
    	form->priv = priv;
     
    	gtk_widget_set_has_window(GTK_WIDGET(form), TRUE);
     
    	gtk_widget_set_redraw_on_allocate (GTK_WIDGET (form), TRUE);
    }
     
    GtkWidget* gtk_form_new ()
    {
    	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)
    {
    	/** je suppose ici que une fois gtk_container_add(GTK_CONTAINER(form), widget);
             * a rajouté un widget dans la liste, cette commande permet d'appliquer la contrainte
             * il faut donc le trouver et le traiter
             * transfo utilisation de la structure privée nécessaire **/
    	GtkFormChild *form_child;
     
    	g_return_if_fail (GTK_IS_FORM (form));
    	g_return_if_fail (GTK_IS_WIDGET (child));
     
    	#ifdef CB_TEST
    		g_print ("trace avant appel gtk_form_find_child %d\n", __LINE__); 
    	#endif
    	// c'est ici qu'on le cherche
    	form_child = gtk_form_find_child (form, child);
    	if (!form_child)
    	return;
    	// arrivé ici on l'a sous le coude et on applique les contraintes
    	#ifdef CB_TEST
    		g_print ("gtk_form_constrain en action widget trouvé \n"); 
    	#endif
     
    	form_child->constraints[edge].location = 0;
    	form_child->constraints[edge].attachment = attachment;
    	form_child->constraints[edge].offset = offset;
    	#ifdef CB_TEST
    		g_print ("trace avant appel gtk_form_find_child ici normal widget est NULL c'est la commande %d\n", __LINE__); 
    	#endif
    	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);
    	//}
     
     
    	// je teste l'application des contraintes sur le widget traité via la structure privé???
     
    	//if ( gtk_widget_get_visible (form_child->widget))
    		//if (gtk_widget_get_mapped (form_child->widget))
    			//gtk_widget_map (form_child->widget);
    	//gtk_widget_queue_resize (child);
    	// peut-être commande trop globale ??
    	if (gtk_widget_get_visible (GTK_WIDGET (form)))
    			gtk_widget_queue_resize (GTK_WIDGET (form));
    }
     
    static void gtk_form_finalize (GObject *object)
    {
    	g_return_if_fail (GTK_IS_FORM (object));
    	#ifdef CB_TEST
    		g_print ("gtk_form_finalize\n");
    	#endif
     
    	//GtkForm * form = GTK_FORM (object);
    	//GtkFormPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE(form, GTK_TYPE_FORM, GtkFormPrivate);
    	//// a voir si je dois libérer des ressources au moins la Glist?
     
    	//GList *children = priv->children;
     
    	//GtkFormChild *child;
     
    	//while (children)
        //{
    		//child = children->data;
    		//children = g_list_remove (children, child);
    		//g_free (child);	
        //}
     
      /* Always chain up to the parent class; as with dispose(), finalize()
       * is guaranteed to exist on the parent's class virtual function table
       */
     
    	G_OBJECT_CLASS (parent_class)->finalize (object);
    }
     
    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 (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 (GTK_FORM (widget));
    	#ifdef CB_TEST
    		g_print ("gtk_form_get_preferred_width\n");
    	#endif
    	GtkRequisition requisition;
    	GtkForm *form = GTK_FORM (widget);
    	GtkFormPrivate *priv = gtk_form_get_instance_private (form);
    	GList *list;
     
     
    	gint my_bounds [4] = { 0, 0, 0, 0 };
     
    	gtk_form_size_request (widget, &requisition);
    	*minimal_width = *natural_width = requisition.width;
    	for (list = priv->children; list; list = list->next)
    	{
    		GtkRequisition minimum_size;
            GtkRequisition natural_size; // non utilisé ?
    		GtkFormChild *child = list->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 (list = priv->children; list; list = list->next)
    	{
    		GtkFormChild *child = list->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 (GTK_FORM (widget));
    	#ifdef CB_TEST
    		g_print ("gtk_form_get_preferred_height\n");
    	#endif
    	GtkRequisition requisition;
    	GList *list;
    	GtkForm *form = GTK_FORM (widget);
    	GtkFormPrivate *priv = gtk_form_get_instance_private (form);
    	gint my_bounds [4] = { 0, 0, 0, 0 };
     
    	gtk_form_size_request (widget, &requisition);
    	*minimal_height = *natural_height = requisition.height;
    	for (list = priv->children; list; list = list->next)
    	{
    		GtkRequisition minimum_size;
            GtkRequisition natural_size; // non utilisé ?
    		GtkFormChild *child = list->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 (list = priv->children; list; list = list->next)
    	{
    		GtkFormChild *child = list->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)
    {
    	g_return_if_fail (GTK_FORM (widget));
    	g_return_if_fail (allocation != NULL);
    	gint my_bounds [4];
    	#ifdef CB_TEST
    		g_print(" gtk_form_size_allocate passe ici %d\n", __LINE__); 
    	#endif
    	gtk_widget_set_allocation(widget, allocation);
    	GtkForm *form = GTK_FORM (widget);
     
    	GtkFormPrivate *priv = gtk_form_get_instance_private (form);
     
    	GList *list;
     
    	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);
     
    	for (list = priv->children; list; list = list->next)
    	{
    		GtkFormChild *child = list->data;
    		GtkAllocation allocation;
     
    		allocation.x = child->constraints [GTK_FORM_EDGE_LEFT].location +
    				allocation_form.x + gtk_container_get_border_width(GTK_CONTAINER (form));
     
    		allocation.y = child->constraints [GTK_FORM_EDGE_TOP].location +
    				allocation_form.y + gtk_container_get_border_width(GTK_CONTAINER (form));
     
    		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)
    {
    	/** pour moi c'est ici que la commande gtk_container_add(GTK_CONTAINER(form), widget);
             * va entrer en action par subtitution/complément de gtk_container_add
             * notamment rajouter l'enfant à la liste privée
             **/
     
    	g_return_if_fail (GTK_IS_FORM (container));
    	g_return_if_fail (widget != NULL);
    	/** je comprend avec la commande si dessous que si le wiget a déjà un parent
             * cela va être difficile de le sortir de l'autre structure pour le coller va générer un conflit
             **/
    	#ifdef CB_TEST
    		g_print ("gtk_form_add en action %d\n", __LINE__); 
    	#endif
    	gint i;
     
    	GtkForm * form = GTK_FORM (container);
    	GtkFormPrivate *priv = gtk_form_get_instance_private (form);
     
    	//création et remplissage de la structure form_child
    	GtkFormChild *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;
    	}
    	priv->children = g_list_prepend (priv->children, form_child);
    	// tient c'est ici qu'on définit que l'enfant à un parent et c'est le container bon ok!!
    	/** gtk_widget_set_parent (GtkWidget *widget,
                           GtkWidget *parent);
         * This function is useful only when implementing subclasses of GtkContainer.
         * Sets the container as the parent of widget , and takes care of some details
         * such as updating the state and style of the child to reflect its new location
         **/
    	gtk_widget_set_parent (widget, GTK_WIDGET (form));
    }
     
    static void gtk_form_remove (GtkContainer *container, GtkWidget    *widget)
    {
    	/** je suppose ici qu'il faut retirer un widget du container initial
             * transfo utilisation de la structure privée nécessaire **/
    	g_return_if_fail (GTK_IS_FORM (container));
    	g_return_if_fail (GTK_FORM (widget));
     
    	GtkFormChild *child;
     
    	GtkForm *form = GTK_FORM (container);
     
    	GtkFormPrivate *priv = gtk_form_get_instance_private (form);
    	GList *list = priv->children;
     
    	while (list)
        {
    		child = list->data;
    		list = list->next;
     
    		if (child->widget == widget)
    		{
    		  gtk_widget_unparent (widget);
     
    		  list = g_list_remove (list, 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)
    {
    	GtkFormChild *child;
     
    	g_return_if_fail (GTK_IS_FORM (container));
    	g_return_if_fail (callback != NULL);
     
    	GtkForm *form = GTK_FORM (container);
    	GtkFormPrivate *priv = gtk_form_get_instance_private (form);
    	GList *list = priv->children;
     
    	while (list)
        {
          child = list->data;
          list = list->next;
     
          (* callback) (child->widget, callback_data);
        }
    }
     
    static void gtk_form_layout (GtkForm *form, gint *my_bounds, gboolean recompute_our_size)
    {
        int count;
        g_return_if_fail (GTK_FORM (form));
        GtkFormPrivate *priv = gtk_form_get_instance_private (form);
        for (count = 0; count < 10000; )
        {
            GList *list;
    		gboolean it_worked = 1;
     
    		/** Reset the state of all edges. **/
     
    		for (list = priv->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 = priv->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)
    	    g_print ("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:
    		    g_print ("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 (GTK_FORM (widget));
    	#ifdef CB_TEST
    		g_print ("gtkform_realize %d\n", __LINE__); 
    	#endif
     
    	GtkForm *form = GTK_FORM (widget);
    	GtkFormPrivate *priv = gtk_form_get_instance_private (form);
     
    	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 toujours mon code de test non optimisé par rapport au tien pour comparer

    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
     
    #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);
    	}
        /* 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);
    	}
        /* 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);
    	}
        /* 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);
    	}
     
        /* 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_all(window);
        gtk_main ();
     
        return 0;
    }
    nota dans le source j'ai changé la taille

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    const gint HEIGHT = 200;
    const gint WIDTH = 300;
    et j'ai fait varier self à TRUE ou FALSE

    En effet en testant de près le résulat, tu pourras te rendre compte que la taille des boutons 1 à 3 est compatible avec la zone de clic sauf pour le bouton 4. Ci dessous dans l'image j'ai capturé létat quand on clique sur le côté gauche du bouton 4 ca réagit si je vais dans la zone de droite nada
    Nom : Sélection_144.png
Affichages : 183
Taille : 9,0 Ko

    je soupconne un oubli dans gtk_form_constrain, je creuse

  10. #10
    Expert confirmé
    Avatar de gerald3d
    Homme Profil pro
    Conducteur de train
    Inscrit en
    Février 2008
    Messages
    2 291
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Conducteur de train
    Secteur : Transports

    Informations forums :
    Inscription : Février 2008
    Messages : 2 291
    Points : 4 941
    Points
    4 941
    Billets dans le blog
    5
    Par défaut
    Bonjour turboiii.

    Au risque de me répéter le pointeur priv est initialisé par la macro G_DEFINE_TYPE_WITH_PRIVATE(). Donc la ligne 402 est inutile voir peux poser des problèmes.
    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
    static void gtk_form_init (GtkForm *form)
    {
    #ifdef CB_TEST
      g_print ("gtk_form_init\n");
    #endif
      GtkFormPrivate *priv = gtk_form_get_instance_private (form);
     
      /* Set default values */
      priv->children            = NULL;
      priv->window              = NULL;
     
      /* Create cache for faster access */
      form->priv = priv;
     
      gtk_widget_set_has_window(GTK_WIDGET(form), TRUE);
     
      gtk_widget_set_redraw_on_allocate (GTK_WIDGET (form), TRUE);
    }
    Toujours dans la même fonction quel intérêt d'indiquer que la fenêtre à un GdkWindow ? La documentation officielle indique bien que tous les widgets construits disposent toujours d'un GdkWindow :
    Note that all realized widgets have a non-NULL “window” pointer (gtk_widget_get_window() never returns a NULL window when a widget is realized)...
    Cette ligne est inutile.

    La dernière ligne est du même acabit. Par défaut le widget est redessiné lorsque sa taille change. Tu peux aussi supprimer cette ligne.

    Dans la fonction suivante tu te poses la question pourquoi widget peut être NULL :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    static GtkFormChild *gtk_form_find_child (GtkForm *form, GtkWidget *widget)
    {
      /** ici on va détecter la présence d'un widget enfant dans la liste du container form **/
     
      if (widget == NULL)
        g_print (" WARNING ici widget est NULL pourquoi ? %d\n", __LINE__); 
      else
      ...
    La réponse vient de l'appel dans gtk_form_constrain (); pour le paramètre widget ligne 448. Pour le bouton 1 tu transmets bien NULL. C'est donc une situation normale pour la fonction GtkFormChild *gtk_form_find_child ();.

    Partant de ce constat il faut ajouté un test pour vérifier si widget est NULL. Si tel est le cas on quitte normalement la fonction. Dans le cas contraire alors on teste s'il est du bon type.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    static GtkFormChild *gtk_form_find_child (GtkForm *form, GtkWidget *widget)
    {
      /** ici on va détecter la présence d'un widget enfant dans la liste du container form **/
     
      if (widget == NULL)
        g_print (" WARNING ici widget est NULL pourquoi ? %d\n", __LINE__); 
      else
        g_print (" ici widget est consistant\n");
      g_return_val_if_fail (GTK_IS_FORM (form), NULL);
      if (!widget) return NULL;
      g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
      GtkFormPrivate *priv = gtk_form_get_instance_private (form);
    Pour l'instant cela ne résout rien du problème mais l'idée est de nettoyé le plus possible le code source. Moins il y a de lignes mieux on se porte.

    Le problème se situe de toute manière dans la taille allouée aux widgets enfants. Ils sont affichés en entier mais leur surface réels utilisables est restreinte par rapport à leur taille affichée. D'où le problème de réaction de la souris.

  11. #11
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    147
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 147
    Points : 88
    Points
    88
    Par défaut
    Merci de ta patience.

    Tu as raison d'insister. Du coup je cherche et je progresse.
    ET JE NETTOIE MON CODE
    bon j'ai essayé de mettre la ligne 14 en rouge comment fais tu?
    J'ai rajouté cette ligne juste pour comprendre ce qui se passe...
    avec cette ligne effectvement il n'y a plus de contrainte appliquée du coup plus de défaut non plus. C'est le début de l'enquête.


    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
    void gtk_form_constrain (GtkForm         *form,
                GtkWidget         *child,
                GtkFormEdge       edge,
                GtkFormAttachment attachment,
                GtkWidget        *widget,
                gint              offset)
    {
        /** je suppose ici que une fois gtk_container_add(GTK_CONTAINER(form), widget);
         * a rajouté un widget dans la liste, cette commande permet d'appliquer la contrainte
         * il faut donc le trouver et le traiter
         * transfo utilisation de la structure privée nécessaire ? non à priori**/
    
        /** rajouter la ligne ci-dessous c'est ne pas appliquer de contrainte si pas de widget**/
        g_return_if_fail (GTK_IS_WIDGET (widget));
        g_return_if_fail (GTK_IS_FORM (form));
        g_return_if_fail (GTK_IS_WIDGET (child));
        #ifdef CB_TEST
            g_print ("trace avant appel gtk_form_find_child %d\n", __LINE__); 
        #endif
        // c'est ici qu'on le cherche
        GtkFormChild *form_child = gtk_form_find_child (form, child);
        if (!form_child)
        return;
        // arrivé ici on l'a sous le coude et on applique les contraintes
        #ifdef CB_TEST
            g_print ("gtk_form_constrain en action widget trouvé \n"); 
        #endif
    
        form_child->constraints[edge].location = 0;
        form_child->constraints[edge].attachment = attachment;
        form_child->constraints[edge].offset = offset;
        #ifdef CB_TEST
            g_print ("trace avant appel gtk_form_find_child ici normal widget est NULL c'est la commande %d\n", __LINE__); 
        #endif
        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);
        //}
        if (gtk_widget_get_visible (GTK_WIDGET (child)))
            /** This function is only for use in widget implementations.
             * Causes a widget to be mapped if it isn’t already.**/
            gtk_widget_map (child);
        gtk_widget_queue_resize (GTK_WIDGET (child));
    }

  12. #12
    Expert confirmé
    Avatar de gerald3d
    Homme Profil pro
    Conducteur de train
    Inscrit en
    Février 2008
    Messages
    2 291
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Conducteur de train
    Secteur : Transports

    Informations forums :
    Inscription : Février 2008
    Messages : 2 291
    Points : 4 941
    Points
    4 941
    Billets dans le blog
    5
    Par défaut
    Ca avance ca avance .

    Pour passer un texte dans une autre couleur tu le sélectionnes et tu cliques sur l'icône "A" avec la petite flèche vers le bas. Un panel de couleurs apparaît. Tu fais ton choix et le tour est joué .

Discussions similaires

  1. Desactiver temporairement les contraintes
    Par maitrebn dans le forum MS SQL Server
    Réponses: 4
    Dernier message: 05/10/2006, 17h58
  2. [ contrainte ] supprimer une contrainte DB2
    Par hocinema dans le forum DB2
    Réponses: 4
    Dernier message: 08/01/2004, 15h01
  3. Les contraintes OCL
    Par bart64 dans le forum Langage SQL
    Réponses: 7
    Dernier message: 19/12/2003, 18h47
  4. Suppression de la contrainte unique
    Par mika dans le forum SQL
    Réponses: 3
    Dernier message: 20/02/2003, 17h56
  5. [VB6] Affichage d'image avec qlq contraintes
    Par youri dans le forum VB 6 et antérieur
    Réponses: 3
    Dernier message: 21/11/2002, 14h44

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo