Bonjour.
Je me lance à corps perdu dans la tentative de création d'un widget personnel. Pour se faire je me suis largement inspiré de l'excellent tutoriel de Franck.H. Mais vous vous en doutez, si j'écris ici, c'est que je suis tombé sur un os !
Tout d'abord, au regard du tutoriel qui commence à dater, beaucoup de choses sont devenues obsolètes. Je me suis donc reporté à la documentation officielle pour trier le grain de l'ivraie. . Il existe maintenant des macros qui s'implifient l'écriture. Finalement rien de bien gênant de prime abord.
Mon code source est maintenant fiable à la compilation. Mais le problème est que mon widget n'hérite pas de son parent ! Il devrait normalement dériver d'un GtkTextView mais rien n'y fait. Je vous livre en pâture le header et le code source. Si l'un ou l'une d'entre-vous à la solution...
header file :
source code :
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 #ifndef __GTK_TERM_H__ #define __GTK_TERM_H__ #include <gtk/gtk.h> G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (GtkTerm, gtk_term, GTK, TERM, GtkTextView) #define GTK_TYPE_TERM gtk_term_get_type () typedef struct _GtkTermPrivate GtkTermPrivate; // Création d'une instance. shell peut être NULL (lance bash par défaut) GtkWidget *gtk_term_new (const gchar *shell); G_END_DECLS #endif
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 #include "gtkterm.h" struct _GtkTerm { GtkTextView parent_instance; GtkTermPrivate *priv; }; struct _GtkTermClass { GtkTextViewClass parent_class; }; /* Private structure definition. */ struct _GtkTermPrivate { gchar *shell; } ; G_DEFINE_TYPE_WITH_PRIVATE (GtkTerm, gtk_term, G_TYPE_OBJECT) static void gtk_term_class_init (GtkTermClass *klass); static void gtk_term_init (GtkTerm *term); static void gtk_term_dispose (GObject * object); static void gtk_term_finalize (GObject * object); GtkWidget * gtk_term_new (const gchar *shell) { GtkTerm *term; term = g_object_new (GTK_TYPE_TERM, NULL); GtkTermPrivate *priv = gtk_term_get_instance_private (term); if (shell) priv->shell = g_strdup (shell); else priv->shell = g_strdup_printf ("bash"); return GTK_WIDGET (term); } static void gtk_term_class_init (GtkTermClass *klass) { G_OBJECT_CLASS(klass)->dispose = gtk_term_dispose; G_OBJECT_CLASS(klass)->finalize = gtk_term_finalize; } static void gtk_term_init (GtkTerm *self) { GtkTermPrivate *priv; self->priv = gtk_term_get_instance_private (self); priv = self->priv; priv->shell = NULL; gtk_widget_set_has_window (GTK_WIDGET (self), FALSE); } static void gtk_term_dispose (GObject * object) { GtkTerm *term; g_return_if_fail (object != NULL); g_return_if_fail (GTK_IS_TERM (object)); G_OBJECT_CLASS (gtk_term_parent_class)->dispose (object); } static void gtk_term_finalize (GObject *object) { GtkTermPrivate *priv = gtk_term_get_instance_private (GTK_TERM (object)); g_free (priv->shell); priv->shell = NULL; /* 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 (gtk_term_parent_class)->finalize (object); }
Partager