summaryrefslogtreecommitdiff
path: root/src/glibext/widthtracker.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/glibext/widthtracker.c')
-rw-r--r--src/glibext/widthtracker.c556
1 files changed, 330 insertions, 226 deletions
diff --git a/src/glibext/widthtracker.c b/src/glibext/widthtracker.c
index bfeb32c..7e06578 100644
--- a/src/glibext/widthtracker.c
+++ b/src/glibext/widthtracker.c
@@ -26,6 +26,331 @@
#include <assert.h>
#include <malloc.h>
+
+
+#include "widthtracker-int.h"
+
+
+
+/* ---------------------------- PRISE DE MESURES LOCALES ---------------------------- */
+
+
+/* Supprime de la mémoire une collecte de mesures locales. */
+static void delete_common_metrics(common_metrics_t *);
+
+
+
+/* ---------------------------- RASSEMBLEMENT DE MESURES ---------------------------- */
+
+
+/* Procède à l'initialisation d'une classe de suivi de largeurs. */
+static void g_width_tracker_class_init(GWidthTrackerClass *);
+
+/* Procède à l'initialisation d'un suivi de largeurs de lignes. */
+static void g_width_tracker_init(GWidthTracker *);
+
+/* Supprime toutes les références externes. */
+static void g_width_tracker_dispose(GWidthTracker *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_width_tracker_finalize(GWidthTracker *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* PRISE DE MESURES LOCALES */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : metrics = mesures locales conservées. *
+* *
+* Description : Supprime de la mémoire une collecte de mesures locales. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void delete_common_metrics(common_metrics_t *metrics)
+{
+ free(metrics->summary);
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* RASSEMBLEMENT DE MESURES */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Détermine le type du gestionnaire de largeurs associées aux lignes. */
+G_DEFINE_TYPE(GWidthTracker, g_width_tracker, G_TYPE_OBJECT);
+
+
+/******************************************************************************
+* *
+* Paramètres : class = classe de composant GLib à initialiser. *
+* *
+* Description : Procède à l'initialisation d'une classe de suivi de largeurs.*
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_width_tracker_class_init(GWidthTrackerClass *class)
+{
+ GObjectClass *object; /* Autre version de la classe */
+
+ object = G_OBJECT_CLASS(class);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_width_tracker_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_width_tracker_finalize;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : tracker = composant GLib à initialiser. *
+* *
+* Description : Procède à l'initialisation d'un suivi de largeurs de lignes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_width_tracker_init(GWidthTracker *tracker)
+{
+ tracker->cache = NULL;
+ tracker->opt_count = 0;
+ tracker->reg_count = 0;
+
+ tracker->locals = NULL;
+ tracker->count = 0;
+
+ tracker->min_widths = NULL;
+ tracker->fixed = NULL;
+ tracker->cached = false;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : tracker = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_width_tracker_dispose(GWidthTracker *tracker)
+{
+ g_clear_object(&tracker->cache);
+
+ G_OBJECT_CLASS(g_width_tracker_parent_class)->dispose(G_OBJECT(tracker));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : tracker = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_width_tracker_finalize(GWidthTracker *tracker)
+{
+ size_t i; /* Boucle de parcours */
+
+ for (i = 0; i < tracker->count; i++)
+ delete_common_metrics(&tracker->locals[i]);
+
+ if (tracker->locals != NULL)
+ free(tracker->locals);
+
+ if (tracker->min_widths != NULL)
+ free(tracker->min_widths);
+
+ if (tracker->fixed != NULL)
+ free(tracker->fixed);
+
+ G_OBJECT_CLASS(g_width_tracker_parent_class)->finalize(G_OBJECT(tracker));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : cache = tampon de lignes à lier au futur collecteur. *
+* *
+* Description : Crée un nouveau suivi de largeurs au sein de lignes. *
+* *
+* Retour : Composant GLib créé. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GWidthTracker *g_width_tracker_new(GBufferCache *cache)
+{
+ GWidthTracker *result; /* Composant à retourner */
+
+ result = g_object_new(G_TYPE_WIDTH_TRACKER, NULL);
+
+ if (!g_width_tracker_create(result, cache))
+ g_clear_object(&result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : tracker = collecteur de largeur à initialiser pleinement. *
+* cache = tampon de lignes à lier au futur élément. *
+* *
+* Description : Met en place un nouveau suivi de largeurs au sein de lignes. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_width_tracker_create(GWidthTracker *tracker, GBufferCache *cache)
+{
+ bool result; /* Bilen à retourner */
+ size_t col_count; /* Nombre maximum de colonnes */
+
+ result = true;
+
+ tracker->cache = cache;
+ ref_object(cache);
+
+ g_buffer_cache_count_columns(cache, &tracker->opt_count, &tracker->reg_count);
+
+ col_count = tracker->opt_count + tracker->reg_count;
+
+#ifndef NDEBUG
+ tracker->col_count = col_count;
+#endif
+
+ tracker->min_widths = malloc(col_count * sizeof(int));
+ tracker->fixed = calloc(col_count, sizeof(bool));
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : tracker = gestionnaire de largeurs de lignes à mettre jour. *
+* col = indice de colonne visée. *
+* *
+* Description : Indique la largeur minimale pour une colonne donnée. *
+* *
+* Retour : Largeur minimale à imposée, nulle ou positive. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int g_width_tracker_get_column_min_width(const GWidthTracker *tracker, size_t col)
+{
+ int result; /* Largeur à renvoyer */
+
+ assert(col < tracker->col_count);
+
+ result = tracker->min_widths[col];
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : tracker = gestionnaire de largeurs de lignes à mettre jour. *
+* col = indice de colonne visée. *
+* width = largeur minimale à imposer. *
+* *
+* Description : Impose une largeur minimale pour une colonne donnée. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_width_tracker_set_column_min_width(GWidthTracker *tracker, size_t col, int width)
+{
+ assert(col < tracker->col_count);
+
+ if (width < 0)
+ width = 0;
+
+ tracker->min_widths[col] = width;
+ tracker->fixed[col] = true;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : tracker = gestionnaire de largeurs de lignes à consulter. *
+* width = largeur requise pour un affichage complet. [OUT] *
+* *
+* Description : Détermine la largeur nécessaire à une pleine représentation. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_width_tracker_compute_width(const GWidthTracker *tracker, int *width)
+{
+ size_t i; /* Boucle de parcours */
+
+ *width = 0;
+
+ // FIX access to col_count
+
+ for (i = 0; i < tracker->col_count; i++)
+ *width += tracker->min_widths[i];
+
+}
+
+
+
+
+
+
+#if 0
+
+
+//#include <assert.h>
+//#include <malloc.h>
#include <stdlib.h>
#include <string.h>
@@ -33,7 +358,7 @@
#include <i18n.h>
-#include "buffercache.h"
+//#include "buffercache.h"
#include "delayed-int.h"
#include "../core/global.h"
#include "../core/nproc.h"
@@ -104,56 +429,7 @@ static void g_width_update_collect(GWidthUpdate *, line_width_summary *);
/* ---------------------------- RASSEMBLEMENT DE MESURES ---------------------------- */
-/* Portions de largeurs communes */
-typedef struct _common_metrics
-{
- size_t first; /* Premier indice de portion */
- size_t last; /* Dernier indice de portion */
-
- line_width_summary summary; /* Compilation de largeurs */
- bool cached; /* Mise en cache des calculs */
-
-} common_metrics;
-
-
-/* Gestionnaire de largeurs associées aux lignes (instance) */
-struct _GWidthTracker
-{
- GObject parent; /* A laisser en premier */
-
- GBufferCache *cache; /* Ensemble complet de lignes */
- size_t col_count; /* Nombre maximum de colonnes */
- size_t opt_count; /* Qté de colonnes en option */
-
- common_metrics *portions; /* Portions représentées */
- size_t count; /* Quantité de ces portions */
-
- gint *min_widths; /* Largeurs min. à respecter */
-
- line_width_summary summary; /* Largeurs requises suivies */
- bool cached; /* Mise en cache des calculs */
-
-};
-
-/* Gestionnaire de largeurs associées aux lignes (classe) */
-struct _GWidthTrackerClass
-{
- GObjectClass parent; /* A laisser en premier */
-
-};
-
-
-/* Procède à l'initialisation d'une classe de suivi de largeurs. */
-static void g_width_tracker_class_init(GWidthTrackerClass *);
-
-/* Procède à l'initialisation d'un suivi de largeurs de lignes. */
-static void g_width_tracker_init(GWidthTracker *);
-/* Supprime toutes les références externes. */
-static void g_width_tracker_dispose(GWidthTracker *);
-
-/* Procède à la libération totale de la mémoire. */
-static void g_width_tracker_finalize(GWidthTracker *);
/* Recherche la portion contenant un indice de ligne donné. */
static size_t g_width_tracker_find_metrics(const GWidthTracker *, size_t);
@@ -375,131 +651,6 @@ static void g_width_update_collect(GWidthUpdate *update, line_width_summary *glo
/* ---------------------------------------------------------------------------------- */
-/* Détermine le type du gestionnaire de largeurs associées aux lignes. */
-G_DEFINE_TYPE(GWidthTracker, g_width_tracker, G_TYPE_OBJECT);
-
-
-/******************************************************************************
-* *
-* Paramètres : class = classe de composant GTK à initialiser. *
-* *
-* Description : Procède à l'initialisation d'une classe de suivi de largeurs.*
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void g_width_tracker_class_init(GWidthTrackerClass *class)
-{
- GObjectClass *object; /* Autre version de la classe */
-
- object = G_OBJECT_CLASS(class);
-
- object->dispose = (GObjectFinalizeFunc/* ! */)g_width_tracker_dispose;
- object->finalize = (GObjectFinalizeFunc)g_width_tracker_finalize;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : tracker = composant GLib à initialiser. *
-* *
-* Description : Procède à l'initialisation d'un suivi de largeurs de lignes. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void g_width_tracker_init(GWidthTracker *tracker)
-{
- tracker->portions = NULL;
- tracker->count = 0;
-
- memset(&tracker->summary, 0, sizeof(line_width_summary));
- tracker->cached = false;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : tracker = instance d'objet GLib à traiter. *
-* *
-* Description : Supprime toutes les références externes. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void g_width_tracker_dispose(GWidthTracker *tracker)
-{
- g_object_unref(G_OBJECT(tracker->cache));
-
- G_OBJECT_CLASS(g_width_tracker_parent_class)->dispose(G_OBJECT(tracker));
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : tracker = instance d'objet GLib à traiter. *
-* *
-* Description : Procède à la libération totale de la mémoire. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void g_width_tracker_finalize(GWidthTracker *tracker)
-{
- if (tracker->min_widths != NULL)
- free(tracker->min_widths);
-
- G_OBJECT_CLASS(g_width_tracker_parent_class)->finalize(G_OBJECT(tracker));
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : cache = tampon de lignes à lier au futur élément. *
-* col_count = quantité maximale de colonnes à considérer. *
-* opt_count = quantité de colonnes optionnelles. *
-* *
-* Description : Crée un nouveau suivi de largeurs au sein de lignes. *
-* *
-* Retour : Composant GLib créé. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-GWidthTracker *g_width_tracker_new(GBufferCache *cache, size_t col_count, size_t opt_count)
-{
- GWidthTracker *result; /* Composant à retourner */
-
- result = g_object_new(G_TYPE_WIDTH_TRACKER, NULL);
-
- g_object_ref(G_OBJECT(cache));
- result->cache = cache;
-
- result->col_count = col_count;
- result->opt_count = opt_count;
-
- result->min_widths = calloc(col_count, sizeof(gint));
-
- return result;
-
-}
/******************************************************************************
@@ -588,57 +739,6 @@ size_t g_width_tracker_count_columns(const GWidthTracker *tracker)
}
-/******************************************************************************
-* *
-* Paramètres : tracker = gestionnaire de largeurs de lignes à mettre jour. *
-* col = indice de colonne visée. *
-* *
-* Description : Indique la largeur minimale pour une colonne donnée. *
-* *
-* Retour : Largeur minimale à imposée, nulle ou positive. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-gint g_width_tracker_get_column_min_width(GWidthTracker *tracker, size_t col)
-{
- gint result; /* Largeur à renvoyer */
-
- assert(col < tracker->col_count);
-
- result = tracker->min_widths[col];
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : tracker = gestionnaire de largeurs de lignes à mettre jour. *
-* col = indice de colonne visée. *
-* width = largeur minimale à imposer. *
-* *
-* Description : Impose une largeur minimale pour une colonne donnée. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-void g_width_tracker_set_column_min_width(GWidthTracker *tracker, size_t col, gint width)
-{
- assert(col < tracker->col_count);
-
- if (width < 0)
- width = 0;
-
- tracker->min_widths[col] = width;
-
-}
-
/******************************************************************************
* *
@@ -1367,3 +1467,7 @@ gint g_width_tracker_get_local_column_width(GWidthTracker *tracker, size_t index
return result;
}
+
+
+#endif
+