summaryrefslogtreecommitdiff
path: root/src/gtkext/gtkdockstation.c
blob: 2a0d1887781fe70c08a4048e62fdd2e179440570 (plain)
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

/* OpenIDA - Outil d'analyse de fichiers binaires
 * gtkdockstation.c - manipulation et l'affichage de composants rassemblés
 *
 * Copyright (C) 2012 Cyrille Bagard
 *
 *  This file is part of OpenIDA.
 *
 *  OpenIDA is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  OpenIDA is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 */


#include "gtkdockstation.h"


#include <malloc.h>
#include <string.h>


#include "easygtk.h"
#include "iodamarshal.h"
#include "../params.h"
#include "../common/extstr.h"



/* Procède à l'initialisation de l'afficheur concentré. */
static void gtk_dock_station_class_init(GtkDockStationClass *);

/* Procède à l'initialisation du support d'affichage concentré. */
static void gtk_dock_station_init(GtkDockStation *);

/* Met à jour le titre du support de panneaux concentrés. */
static gboolean gtk_dock_station_switch_panel(GtkNotebook *, gpointer *, guint, gpointer);



/* Détermine le type du composant d'affichage concentré. */
G_DEFINE_TYPE(GtkDockStation, gtk_dock_station, GTK_TYPE_VBOX)


/******************************************************************************
*                                                                             *
*  Paramètres  : class = classe GTK à initialiser.                            *
*                                                                             *
*  Description : Procède à l'initialisation de l'afficheur concentré.         *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void gtk_dock_station_class_init(GtkDockStationClass *class)
{
    g_signal_new("switch-widget",
                 GTK_TYPE_DOCK_STATION,
                 G_SIGNAL_RUN_LAST,
                 G_STRUCT_OFFSET(GtkDockStationClass, switch_widget),
                 NULL, NULL,
                 g_cclosure_user_marshal_VOID__OBJECT,
                 G_TYPE_NONE, 1, GTK_TYPE_WIDGET);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : station = composant GTK à initialiser.                       *
*                                                                             *
*  Description : Procède à l'initialisation du support d'affichage concentré. *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void gtk_dock_station_init(GtkDockStation *station)
{
    GtkWidget *eventbox;                    /* Réceptacle actif            */
    GtkWidget *hbox;                        /* Division supérieure         */
    GtkWidget *button;                      /* Bouton de contrôle          */
    GtkWidget *image;                       /* Image associée              */

    eventbox = gtk_event_box_new();
    gtk_widget_show(eventbox);
    gtk_box_pack_start(GTK_BOX(station), eventbox, FALSE, TRUE, 0);

    hbox = gtk_hbox_new(FALSE, 0);
    gtk_widget_show(hbox);
    gtk_container_add(GTK_CONTAINER(eventbox), hbox);

    station->title = GTK_LABEL(gtk_label_new(("<b>titre</b>")));
    gtk_widget_show(GTK_WIDGET(station->title));
    gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(station->title), TRUE, TRUE, 0);
    gtk_label_set_use_markup(GTK_LABEL(station->title), TRUE);
    gtk_misc_set_alignment(GTK_MISC(station->title), 0, 0.5);

    button = gtk_button_new();
    gtk_widget_show(button);
    gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
    gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);

    image = gtk_image_new_from_stock("gtk-media-play", GTK_ICON_SIZE_MENU);
    gtk_widget_show(image);
    gtk_container_add(GTK_CONTAINER(button), image);
    gtk_widget_set_size_request(image, 10, 10);

    button = gtk_button_new();
    gtk_widget_show(button);
    gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
    gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);

    image = gtk_image_new_from_stock("gtk-close", GTK_ICON_SIZE_MENU);
    gtk_widget_show(image);
    gtk_container_add(GTK_CONTAINER(button), image);
    gtk_widget_set_size_request(image, 10, 10);

    station->notebook = GTK_NOTEBOOK(gtk_notebook_new());
    gtk_widget_show(GTK_WIDGET(station->notebook));
    gtk_box_pack_start(GTK_BOX(station), GTK_WIDGET(station->notebook), TRUE, TRUE, 0);
    gtk_notebook_set_show_border(station->notebook, FALSE);
    gtk_notebook_set_tab_pos(station->notebook, GTK_POS_BOTTOM);
    gtk_notebook_set_scrollable(station->notebook, TRUE);

    g_signal_connect(station->notebook, "switch-page",
                     G_CALLBACK(gtk_dock_station_switch_panel), station);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : -                                                            *
*                                                                             *
*  Description : Crée un nouveau composant pour support d'affichage concentré.*
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

GtkWidget *gtk_dock_station_new(void)
{
    return g_object_new(GTK_TYPE_DOCK_STATION, NULL);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : notebook = support à l'origine de la mise à jour.            *
*                page     = onglet mis en avant.                              *
*                index    = indice de l'onglet actuellement actif.            *
*                data     = adresse du conteneur supérieur.                   *
*                                                                             *
*  Description : Met à jour le titre du support de panneaux concentrés.       *
*                                                                             *
*  Retour      : TRUE ?                                                       *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static gboolean gtk_dock_station_switch_panel(GtkNotebook *notebook, gpointer *page, guint index, gpointer data)
{
    GtkWidget *widget;                      /* Panneau concerné            */
    char *caption;                          /* Texte à redonner            */

    widget = gtk_notebook_get_nth_page(notebook, index);
    caption = g_object_get_data(G_OBJECT(widget), "title");

    gtk_dock_panel_update_title(GTK_DOCK_STATION(data), widget, caption);

    g_signal_emit_by_name(GTK_DOCK_STATION(data), "switch-widget", widget);

    return TRUE;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : station = plateforme GTK à compléter.                        *
*                widget  = nouvel élément à intégrer.                         *
*                caption = intitulé court à afficher sur les onglets.         *
*                                                                             *
*  Description : Ajoute un paquet d'informations à l'affichage centralisé.    *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

void gtk_dock_panel_add_widget(GtkDockStation *station, GtkWidget *widget, const char *caption)
{
    size_t max;                             /* Taille maximale des titres  */
    char *str;                              /* Titre des prochaines fois   */
    GtkWidget *label;                       /* Etiquette d'onglet          */

    max = get_integer_config_value(get_main_configuration(), MPT_ELLIPSIS_TAB);

    str = ellipsis(strdup(caption), max);
    label = qck_create_label(NULL, NULL, str);
    free(str);

    g_signal_handlers_disconnect_by_func(station->notebook,
                                         G_CALLBACK(gtk_dock_station_switch_panel), station);

    gtk_notebook_insert_page(station->notebook, widget, label, -1);
    gtk_widget_set_tooltip_text(label, caption);

    g_signal_connect(station->notebook, "switch-page",
                     G_CALLBACK(gtk_dock_station_switch_panel), station);

    gtk_notebook_set_show_tabs(station->notebook, gtk_notebook_get_n_pages(station->notebook) > 1);

    str = g_object_get_data(G_OBJECT(widget), "title");
    if (str != NULL) free(str);
    max = get_integer_config_value(get_main_configuration(), MPT_ELLIPSIS_HEADER);
    g_object_set_data(G_OBJECT(widget), "title", ellipsis(strdup(caption), max));

    gtk_dock_panel_update_title(station, widget, caption);

    gtk_notebook_set_current_page(station->notebook, -1);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : station = plateforme GTK à compléter.                        *
*                widget  = nouvel élément à intégrer.                         *
*                                                                             *
*  Description : Change le contenu de l'onglet courant uniquement.            *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

void gtk_dock_panel_change_active_widget(GtkDockStation *station, GtkWidget *widget)
{
    gint index;                             /* Indice de l'onglet actif    */
    GtkWidget *old;                         /* Ancien composant            */
    GtkWidget *label;                       /* Etiquette d'onglet          */
    char *str;                              /* Titre des prochaines fois   */

    index = gtk_notebook_get_current_page(station->notebook);

    g_signal_handlers_disconnect_by_func(station->notebook,
                                         G_CALLBACK(gtk_dock_station_switch_panel), station);

    old = gtk_notebook_get_nth_page(station->notebook, index);
    label = gtk_notebook_get_tab_label(station->notebook, old);

    g_object_ref(G_OBJECT(old));
    g_object_ref(G_OBJECT(label));
    str = g_object_get_data(G_OBJECT(old), "title");

    gtk_notebook_remove_page(station->notebook, index);
    gtk_notebook_insert_page(station->notebook, widget, label, index);

    g_object_unref(G_OBJECT(label));
    g_object_set_data(G_OBJECT(widget), "title", str);

    gtk_notebook_set_current_page(station->notebook, index);

    g_signal_connect(station->notebook, "switch-page",
                     G_CALLBACK(gtk_dock_station_switch_panel), station);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : station = plateforme GTK à compléter.                        *
*                widget  = nouvel élément à intégrer.                         *
*                                                                             *
*  Description : Retire un paquet d'informations de l'affichage centralisé.   *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

void gtk_dock_panel_remove_widget(GtkDockStation *station, GtkWidget *widget)
{
    gint index;                             /* Indice de l'onglet visé     */

    index = gtk_notebook_page_num(station->notebook, widget);

    gtk_notebook_remove_page(station->notebook, index);

    if (gtk_notebook_get_n_pages(station->notebook) == 0)
        gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(GTK_WIDGET(station))),
                             GTK_WIDGET(station));

}


/******************************************************************************
*                                                                             *
*  Paramètres  : station = plateforme GTK à compléter.                        *
*                widget  = nouvel élément à intégrer.                         *
*                caption = intitulé court à afficher sur les onglets.         *
*                                                                             *
*  Description : Met à jour, si besoin est, le titre de l'affichage concentré.*
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

void gtk_dock_panel_update_title(GtkDockStation *station, GtkWidget *widget, const char *caption)
{
    char *str;                              /* Valeur finale reconstituée  */

    str = calloc(strlen("<b>") + strlen(caption) + strlen("</b>") + 1, sizeof(char));

    strcpy(str, "<b>");
    strcat(str, caption);
    strcat(str, "</b>");

    gtk_label_set_markup(station->title, str);

    free(str);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : station = plateforme GTK à consulter.                        *
*                index   = indice de l'onglet visé.                           *
*                                                                             *
*  Description : Renvoie un composant intégré dans l'affichage centralisé.    *
*                                                                             *
*  Retour      : Composant associé à l'indice donné.                          *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

GtkWidget *gtk_dock_panel_get_widget(GtkDockStation *station, gint index)
{
    return gtk_notebook_get_nth_page(station->notebook, index);

}