diff options
Diffstat (limited to 'src/gtkext')
-rw-r--r-- | src/gtkext/gtkdockitem.c | 106 | ||||
-rw-r--r-- | src/gtkext/gtkdockitem.h | 46 | ||||
-rw-r--r-- | src/gtkext/gtkdockpanel.c | 62 | ||||
-rw-r--r-- | src/gtkext/gtkdockpanel.h | 8 |
4 files changed, 152 insertions, 70 deletions
diff --git a/src/gtkext/gtkdockitem.c b/src/gtkext/gtkdockitem.c index 89d606c..51d1cc7 100644 --- a/src/gtkext/gtkdockitem.c +++ b/src/gtkext/gtkdockitem.c @@ -28,14 +28,24 @@ -/* Détermine le type d'un panneau dockable. */ -G_DEFINE_TYPE(GtkDockItem, gtk_dock_item, GTK_TYPE_OBJECT) +/* Procède à l'initialisation d'un panneau dockable. */ +static void g_dock_item_class_init(GDockItemClass *); + +/* Supprime toutes les références externes. */ +static void g_dock_item_class_dispose(GDockItem *); + +/* Procède à la libération totale de la mémoire. */ +static void g_dock_item_class_finalize(GDockItem *); +/* Détermine le type d'un panneau dockable. */ +G_DEFINE_TYPE(GDockItem, g_dock_item, G_TYPE_OBJECT) + + /****************************************************************************** * * -* Paramètres : class = classe GTK à initialiser. * +* Paramètres : klass = classe GTK à initialiser. * * * * Description : Procède à l'initialisation d'un panneau dockable. * * * @@ -45,12 +55,19 @@ G_DEFINE_TYPE(GtkDockItem, gtk_dock_item, GTK_TYPE_OBJECT) * * ******************************************************************************/ -static void gtk_dock_item_class_init(GtkDockItemClass *class) +static void g_dock_item_class_init(GDockItemClass *klass) { + GObjectClass *object; /* Autre version de la classe */ + + object = G_OBJECT_CLASS(klass); + + object->dispose = g_dock_item_class_dispose; + object->finalize = g_dock_item_class_finalize; + g_signal_new("content-changed", - GTK_TYPE_DOCK_ITEM, + G_TYPE_DOCK_ITEM, G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(GtkDockItemClass, content_changed), + G_STRUCT_OFFSET(GDockItemClass, content_changed), NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_OBJECT, G_TYPE_NONE, 2, GTK_TYPE_WIDGET, GTK_TYPE_WIDGET); @@ -60,6 +77,57 @@ static void gtk_dock_item_class_init(GtkDockItemClass *class) /****************************************************************************** * * +* Paramètres : ditem = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_dock_item_class_dispose(GDockItem *ditem) +{ + gpointer obj_class; /* Classe parente */ + + gtk_widget_unref(ditem->panel); + + obj_class = g_type_class_peek_parent(G_DOCK_ITEM_GET_CLASS(ditem)); + + G_OBJECT_CLASS(obj_class)->dispose(G_OBJECT(ditem)); + +} + + +/****************************************************************************** +* * +* Paramètres : ditem = instance d'objet GLib à traiter. * +* * +* Description : Procède à la libération totale de la mémoire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_dock_item_class_finalize(GDockItem *ditem) +{ + gpointer obj_class; /* Classe parente */ + + g_free(ditem->name); + g_free(ditem->desc); + + obj_class = g_type_class_peek_parent(G_DOCK_ITEM_GET_CLASS(ditem)); + + G_OBJECT_CLASS(obj_class)->finalize(G_OBJECT(ditem)); + +} + + +/****************************************************************************** +* * * Paramètres : ditem = composant GTK à initialiser. * * * * Description : Procède à l'initialisation d'un panneau dockable. * @@ -70,7 +138,7 @@ static void gtk_dock_item_class_init(GtkDockItemClass *class) * * ******************************************************************************/ -static void gtk_dock_item_init(GtkDockItem *ditem) +static void g_dock_item_init(GDockItem *ditem) { ditem->name = NULL; @@ -92,14 +160,14 @@ static void gtk_dock_item_init(GtkDockItem *ditem) * * ******************************************************************************/ -GtkDockItem *gtk_dock_item_new(const gchar *name, GtkWidget *panel) +GDockItem *g_dock_item_new(const gchar *name, GtkWidget *panel) { - GtkDockItem *result; /* Composant à retourner */ + GDockItem *result; /* Composant à retourner */ - result = g_object_new(GTK_TYPE_DOCK_ITEM, NULL); + result = g_object_new(G_TYPE_DOCK_ITEM, NULL); - gtk_dock_item_set_name(result, name); - gtk_dock_item_set_panel(result, panel); + g_dock_item_set_name(result, name); + g_dock_item_set_panel(result, panel); return result; @@ -119,7 +187,7 @@ GtkDockItem *gtk_dock_item_new(const gchar *name, GtkWidget *panel) * * ******************************************************************************/ -void gtk_dock_item_set_name(GtkDockItem *ditem, const gchar *name) +void g_dock_item_set_name(GDockItem *ditem, const gchar *name) { if (ditem->name != NULL) g_free(ditem->name); @@ -141,7 +209,7 @@ void gtk_dock_item_set_name(GtkDockItem *ditem, const gchar *name) * * ******************************************************************************/ -const gchar *gtk_dock_item_get_name(GtkDockItem *ditem) +const gchar *g_dock_item_get_name(GDockItem *ditem) { return ditem->name; @@ -161,7 +229,7 @@ const gchar *gtk_dock_item_get_name(GtkDockItem *ditem) * * ******************************************************************************/ -void gtk_dock_item_set_desc(GtkDockItem *ditem, const gchar *desc) +void g_dock_item_set_desc(GDockItem *ditem, const gchar *desc) { if (ditem->desc != NULL) g_free(ditem->desc); @@ -183,14 +251,14 @@ void gtk_dock_item_set_desc(GtkDockItem *ditem, const gchar *desc) * * ******************************************************************************/ -const gchar *gtk_dock_item_get_desc(GtkDockItem *ditem) +const gchar *g_dock_item_get_desc(GDockItem *ditem) { const char *result; /* CHaîne à renvoyer */ result = ditem->desc; if (result == NULL) - result = gtk_dock_item_get_name(ditem); + result = g_dock_item_get_name(ditem); return result; @@ -210,7 +278,7 @@ const gchar *gtk_dock_item_get_desc(GtkDockItem *ditem) * * ******************************************************************************/ -void gtk_dock_item_set_panel(GtkDockItem *ditem, GtkWidget *panel) +void g_dock_item_set_panel(GDockItem *ditem, GtkWidget *panel) { GtkWidget *old; /* Ancien panneau remplacé */ @@ -240,7 +308,7 @@ void gtk_dock_item_set_panel(GtkDockItem *ditem, GtkWidget *panel) * * ******************************************************************************/ -GtkWidget *gtk_dock_item_get_panel(GtkDockItem *ditem) +GtkWidget *g_dock_item_get_panel(GDockItem *ditem) { return ditem->panel; diff --git a/src/gtkext/gtkdockitem.h b/src/gtkext/gtkdockitem.h index 851d8de..4e9d1ee 100644 --- a/src/gtkext/gtkdockitem.h +++ b/src/gtkext/gtkdockitem.h @@ -31,21 +31,29 @@ G_BEGIN_DECLS -#define GTK_TYPE_DOCK_ITEM (gtk_dock_item_get_type()) -#define GTK_DOCK_ITEM(obj) GTK_CHECK_CAST(obj, gtk_dock_item_get_type (), GtkDockItem) -#define GTK_DOCK_ITEM_CLASS(klass) GTK_CHECK_CLASS_CAST(klass, gtk_dock_item_get_type(), GtkDockItemClass) -#define GTK_IS_DOCK_ITEM(obj) GTK_CHECK_TYPE(obj, gtk_dock_item_get_type()) +#define G_TYPE_DOCK_ITEM g_dock_item_get_type() +#define G_DOCK_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dock_item_get_type(), GDockItem)) +#define G_IS_DOCK_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dock_item_get_type())) +#define G_DOCK_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DOCK_ITEM, GDockItemClass)) +#define G_IS_DOCK_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DOCK_ITEM)) +#define G_DOCK_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DOCK_ITEM, GDockItemClass)) -typedef struct _GtkDockItem GtkDockItem; -typedef struct _GtkDockItemClass GtkDockItemClass; -struct _GtkDockItem + + +typedef struct _GDockItem GDockItem; +typedef struct _GDockItemClass GDockItemClass; + + + + +struct _GDockItem { - GtkObject object; /* Présence obligatoire en 1er */ + GObject parent; /* A laisser en premier */ gchar *name; /* Nom court pour titre */ gchar *desc; /* Nom long pour onglet */ @@ -54,40 +62,40 @@ struct _GtkDockItem }; -struct _GtkDockItemClass +struct _GDockItemClass { - GtkVBoxClass parent_class; /* Présence obligatoire en 1er */ + GObjectClass parent; /* A laisser en premier */ /* Signaux */ - void (* content_changed) (GtkDockItem *, GtkWidget *, GtkWidget *); + void (* content_changed) (GDockItem *, GtkWidget *, GtkWidget *); }; /* Détermine le type d'un panneau dockable. */ -GtkType gtk_dock_item_get_type(void); +GtkType g_dock_item_get_type(void); /* Crée une nouvelle mémorisation de panneau dockable. */ -GtkDockItem *gtk_dock_item_new(const gchar *, GtkWidget *); +GDockItem *g_dock_item_new(const gchar *, GtkWidget *); /* Change le nom du panneau dockable pour son onglet. */ -void gtk_dock_item_set_name(GtkDockItem *, const gchar *); +void g_dock_item_set_name(GDockItem *, const gchar *); /* Fournit le nom du panneau dockable pour son onglet. */ -const gchar *gtk_dock_item_get_name(GtkDockItem *); +const gchar *g_dock_item_get_name(GDockItem *); /* Change la description du panneau dockable pour son titre. */ -void gtk_dock_item_set_desc(GtkDockItem *, const gchar *); +void g_dock_item_set_desc(GDockItem *, const gchar *); /* Fournit la description du panneau dockable pour son titre. */ -const gchar *gtk_dock_item_get_desc(GtkDockItem *); +const gchar *g_dock_item_get_desc(GDockItem *); /* Change le panneau dockable associé à l'élément. */ -void gtk_dock_item_set_panel(GtkDockItem *, GtkWidget *); +void g_dock_item_set_panel(GDockItem *, GtkWidget *); /* Fournit le panneau dockable associé à l'élément. */ -GtkWidget *gtk_dock_item_get_panel(GtkDockItem *); +GtkWidget *g_dock_item_get_panel(GDockItem *); diff --git a/src/gtkext/gtkdockpanel.c b/src/gtkext/gtkdockpanel.c index 1d9548f..3b74fbb 100644 --- a/src/gtkext/gtkdockpanel.c +++ b/src/gtkext/gtkdockpanel.c @@ -58,13 +58,13 @@ static void gtk_dock_panel_drag_end_cb(GtkDockPanel *, GdkDragContext *, gpointe //static void gtk_dock_panel_drag_data_delete_cb(GtkDockPanel *, GdkDragContext *, gpointer); /* Ajoute un paquet d'informations à la station dockable. */ -static void _gtk_dock_panel_add_item(GtkDockPanel *, GtkDockItem *, gint); +static void _gtk_dock_panel_add_item(GtkDockPanel *, GDockItem *, gint); /* Remplace le panneau d'un membre actuellement affiché. */ -static void on_dock_item_content_changed(GtkDockItem *, GtkWidget *, GtkWidget *, GtkDockPanel *); +static void on_dock_item_content_changed(GDockItem *, GtkWidget *, GtkWidget *, GtkDockPanel *); /* Supprime un paquet d'informations à la station dockable. */ -static void _gtk_dock_panel_remove_item(GtkDockPanel *, GtkDockItem *, GtkWidget *); +static void _gtk_dock_panel_remove_item(GtkDockPanel *, GDockItem *, GtkWidget *); /* Met à jour le titre du support de panneaux dockables. */ static gboolean gtk_dock_panel_update_title(GtkNotebook *, GtkNotebookPage *, guint, gpointer); @@ -130,7 +130,7 @@ static void gtk_dock_panel_class_init(GtkDockPanelClass *class) G_STRUCT_OFFSET(GtkDockPanelClass, switch_item), NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, GTK_TYPE_DOCK_ITEM); + G_TYPE_NONE, 1, G_TYPE_DOCK_ITEM); } @@ -338,7 +338,7 @@ static gboolean gtk_dock_panel_drag_drop_cb(GtkDockPanel *dpanel, GdkDragContext static void gtk_dock_panel_drag_data_received_cb(GtkDockPanel *dpanel, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection, guint target, guint time, gpointer data) { - GtkDockItem *ditem; /* Elément transféré */ + GDockItem *ditem; /* Elément transféré */ gboolean success; /* Bilan de l'opération */ success = FALSE; @@ -347,7 +347,7 @@ static void gtk_dock_panel_drag_data_received_cb(GtkDockPanel *dpanel, GdkDragCo switch (target) { case TARGET_DOCKITEM: - success = (selection->length == sizeof(GtkDockItem *)); + success = (selection->length == sizeof(GDockItem *)); printf(" ## DRAG DATA RCV ## %p\n", dpanel); @@ -356,9 +356,9 @@ static void gtk_dock_panel_drag_data_received_cb(GtkDockPanel *dpanel, GdkDragCo if (success) { - ditem = GTK_DOCK_ITEM(*((GtkDockItem **)selection->data)); + ditem = G_DOCK_ITEM(*((GDockItem **)selection->data)); - printf(" :: get ? %p - %d\n", ditem, GTK_IS_DOCK_ITEM(ditem)); + printf(" :: get ? %p - %d\n", ditem, G_IS_DOCK_ITEM(ditem)); gtk_dock_panel_remove_item(gtk_drag_get_source_widget(context), ditem); gtk_dock_panel_add_item(dpanel, ditem); @@ -480,7 +480,7 @@ static void gtk_dock_panel_drag_begin_cb(GtkDockPanel *dpanel, GdkDragContext *c static void gtk_dock_panel_drag_data_get_cb(GtkDockPanel *dpanel, GdkDragContext *context, GtkSelectionData *selection, guint target, guint time, gpointer data) { gint current; /* Indice de l'onglet courant */ - GtkDockItem *ditem; /* Elément à transférer */ + GDockItem *ditem; /* Elément à transférer */ switch (target) { @@ -490,14 +490,14 @@ static void gtk_dock_panel_drag_data_get_cb(GtkDockPanel *dpanel, GdkDragContext current = gtk_notebook_get_current_page(dpanel->notebook); - ditem = GTK_DOCK_ITEM(g_list_nth_data(dpanel->ditems, current)); + ditem = G_DOCK_ITEM(g_list_nth_data(dpanel->ditems, current)); printf(" %d nth item is %p\n", current, ditem); - printf(" :: set ? %p - %d\n", ditem, GTK_IS_DOCK_ITEM(ditem)); + printf(" :: set ? %p - %d\n", ditem, G_IS_DOCK_ITEM(ditem)); gtk_selection_data_set(selection, selection->target, - 32, (guchar *)&ditem, sizeof(GtkDockItem *)); + 32, (guchar *)&ditem, sizeof(GDockItem *)); break; @@ -540,9 +540,9 @@ static void gtk_dock_panel_drag_end_cb(GtkDockPanel *dpanel, GdkDragContext *con * * ******************************************************************************/ -GtkDockItem *gtk_dock_panel_item_from_name(GtkDockPanel *dpanel, const char *name) +GDockItem *gtk_dock_panel_item_from_name(GtkDockPanel *dpanel, const char *name) { - GtkDockItem *result; /* Trouvaille à remonter */ + GDockItem *result; /* Trouvaille à remonter */ GList *iter; /* Boucle de parcours */ const char *tmp; /* Autre nom à consulter */ @@ -550,10 +550,10 @@ GtkDockItem *gtk_dock_panel_item_from_name(GtkDockPanel *dpanel, const char *nam for (iter = dpanel->ditems; iter != NULL && result == NULL; iter = g_list_next(iter)) { - tmp = gtk_dock_item_get_name(GTK_DOCK_ITEM(iter->data)); + tmp = g_dock_item_get_name(G_DOCK_ITEM(iter->data)); if (strcmp(name, tmp) == 0) - result = GTK_DOCK_ITEM(iter->data); + result = G_DOCK_ITEM(iter->data); } @@ -575,7 +575,7 @@ GtkDockItem *gtk_dock_panel_item_from_name(GtkDockPanel *dpanel, const char *nam * * ******************************************************************************/ -void gtk_dock_panel_add_item(GtkDockPanel *dpanel, GtkDockItem *ditem) +void gtk_dock_panel_add_item(GtkDockPanel *dpanel, GDockItem *ditem) { _gtk_dock_panel_add_item(dpanel, ditem, -1); @@ -596,7 +596,7 @@ void gtk_dock_panel_add_item(GtkDockPanel *dpanel, GtkDockItem *ditem) * * ******************************************************************************/ -static void _gtk_dock_panel_add_item(GtkDockPanel *dpanel, GtkDockItem *ditem, gint position) +static void _gtk_dock_panel_add_item(GtkDockPanel *dpanel, GDockItem *ditem, gint position) { GtkWidget *label; /* Etiquette d'onglet */ @@ -604,10 +604,10 @@ static void _gtk_dock_panel_add_item(GtkDockPanel *dpanel, GtkDockItem *ditem, g printf("[add %p to %p] list len :: %u\n", ditem, dpanel, g_list_length(dpanel->ditems)); - label = gtk_label_new(gtk_dock_item_get_name(ditem)); + label = gtk_label_new(g_dock_item_get_name(ditem)); gtk_widget_show(label); - gtk_notebook_insert_page(dpanel->notebook, gtk_dock_item_get_panel(ditem), label, position); + gtk_notebook_insert_page(dpanel->notebook, g_dock_item_get_panel(ditem), label, position); gtk_notebook_set_show_tabs(dpanel->notebook, g_list_length(dpanel->ditems) > 1); @@ -631,7 +631,7 @@ static void _gtk_dock_panel_add_item(GtkDockPanel *dpanel, GtkDockItem *ditem, g * * ******************************************************************************/ -static void on_dock_item_content_changed(GtkDockItem *ditem, GtkWidget *old, GtkWidget *new, GtkDockPanel *dpanel) +static void on_dock_item_content_changed(GDockItem *ditem, GtkWidget *old, GtkWidget *new, GtkDockPanel *dpanel) { gint position; /* Position de l'onglet à maj */ @@ -639,9 +639,13 @@ static void on_dock_item_content_changed(GtkDockItem *ditem, GtkWidget *old, Gtk g_signal_handlers_disconnect_by_func(dpanel->notebook, G_CALLBACK(gtk_dock_panel_update_title), dpanel); + //g_object_ref(G_OBJECT(ditem)); + _gtk_dock_panel_remove_item(dpanel, ditem, old); _gtk_dock_panel_add_item(dpanel, ditem, position); + //g_object_unref(G_OBJECT(ditem)); + gtk_notebook_set_current_page(dpanel->notebook, position); g_signal_connect(dpanel->notebook, "switch-page", G_CALLBACK(gtk_dock_panel_update_title), dpanel); @@ -663,7 +667,7 @@ static void on_dock_item_content_changed(GtkDockItem *ditem, GtkWidget *old, Gtk * * ******************************************************************************/ -void gtk_dock_panel_remove_item(GtkDockPanel *dpanel, GtkDockItem *ditem) +void gtk_dock_panel_remove_item(GtkDockPanel *dpanel, GDockItem *ditem) { gint pos; /* Position de l'élément visé */ @@ -675,11 +679,13 @@ void gtk_dock_panel_remove_item(GtkDockPanel *dpanel, GtkDockItem *ditem) printf("[rem %p from %p] list len :: %u\n", ditem, dpanel, g_list_length(dpanel->ditems)); - gtk_widget_ref(gtk_dock_item_get_panel(ditem)); - gtk_container_remove(GTK_CONTAINER(dpanel->notebook), gtk_dock_item_get_panel(ditem)); + gtk_widget_ref(g_dock_item_get_panel(ditem)); + gtk_container_remove(GTK_CONTAINER(dpanel->notebook), g_dock_item_get_panel(ditem)); //gtk_notebook_remove_page(dpanel->notebook, pos); + g_object_unref(G_OBJECT(ditem)); + gtk_notebook_set_show_tabs(dpanel->notebook, g_list_length(dpanel->ditems) > 1); } @@ -699,7 +705,7 @@ void gtk_dock_panel_remove_item(GtkDockPanel *dpanel, GtkDockItem *ditem) * * ******************************************************************************/ -static void _gtk_dock_panel_remove_item(GtkDockPanel *dpanel, GtkDockItem *ditem, GtkWidget *panel) +static void _gtk_dock_panel_remove_item(GtkDockPanel *dpanel, GDockItem *ditem, GtkWidget *panel) { gint pos; /* Position de l'élément visé */ @@ -738,7 +744,7 @@ static void _gtk_dock_panel_remove_item(GtkDockPanel *dpanel, GtkDockItem *ditem static gboolean gtk_dock_panel_update_title(GtkNotebook *notebook, GtkNotebookPage *page, guint index, gpointer data) { - GtkDockItem *ditem; /* Elément nouvellement actif */ + GDockItem *ditem; /* Elément nouvellement actif */ const gchar *desc; /* Description à afficher */ char *str; /* Valeur finale reconstituée */ @@ -751,9 +757,9 @@ static gboolean gtk_dock_panel_update_title(GtkNotebook *notebook, GtkNotebookPa //printf(" >> index :: %u vs %d\n", index, gtk_notebook_get_current_page(GTK_DOCK_PANEL(data)->notebook)); - ditem = GTK_DOCK_ITEM(g_list_nth_data(GTK_DOCK_PANEL(data)->ditems, index)); + ditem = G_DOCK_ITEM(g_list_nth_data(GTK_DOCK_PANEL(data)->ditems, index)); - desc = gtk_dock_item_get_desc(ditem); + desc = g_dock_item_get_desc(ditem); str = calloc(strlen("<b>") + strlen(desc) + strlen("</b>") + 1, sizeof(char)); diff --git a/src/gtkext/gtkdockpanel.h b/src/gtkext/gtkdockpanel.h index 2c0cda9..250d6bf 100644 --- a/src/gtkext/gtkdockpanel.h +++ b/src/gtkext/gtkdockpanel.h @@ -68,7 +68,7 @@ struct _GtkDockPanelClass /* Signaux */ - void (* switch_item) (GtkDockPanel *, GtkDockItem *); + void (* switch_item) (GtkDockPanel *, GDockItem *); }; @@ -80,13 +80,13 @@ GtkType gtk_dock_panel_get_type(void); GtkWidget *gtk_dock_panel_new(void); /* Retrouve un membre du panneau d'après son nom. */ -GtkDockItem *gtk_dock_panel_item_from_name(GtkDockPanel *, const char *); +GDockItem *gtk_dock_panel_item_from_name(GtkDockPanel *, const char *); /* Ajoute un paquet d'informations à la station dockable. */ -void gtk_dock_panel_add_item(GtkDockPanel *, GtkDockItem *); +void gtk_dock_panel_add_item(GtkDockPanel *, GDockItem *); /* Supprime un paquet d'informations à la station dockable. */ -void gtk_dock_panel_remove_item(GtkDockPanel *, GtkDockItem *); +void gtk_dock_panel_remove_item(GtkDockPanel *, GDockItem *); |