From 7c07af67784893efd6eb5f7ff51937171ba4628e Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Sun, 29 Apr 2001 20:40:41 +0000 Subject: config file handling added --- mixgtk/mixgtk_fontsel.c | 22 ++++++++++++++++----- mixgtk/mixgtk_mixal.c | 51 ++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 63 insertions(+), 10 deletions(-) diff --git a/mixgtk/mixgtk_fontsel.c b/mixgtk/mixgtk_fontsel.c index 3119825..5f24776 100644 --- a/mixgtk/mixgtk_fontsel.c +++ b/mixgtk/mixgtk_fontsel.c @@ -1,7 +1,7 @@ /* -*-c-*- -------------- mixgtk_fontsel.c : * Implementation of the functions declared in mixgtk_fontsel.h * ------------------------------------------------------------------ - * Last change: Time-stamp: "2001-04-28 23:44:18 jao" + * Last change: Time-stamp: "2001-04-29 16:40:33 jao" * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * @@ -23,6 +23,7 @@ #include #include "mixgtk_widgets.h" +#include "mixgtk_config.h" #include "mixgtk_fontsel.h" static GtkWidget *fontsel_dialog_ = NULL; @@ -33,7 +34,8 @@ typedef struct winfo { GtkWidget *widget; GtkStyle *style; - gchar *font; + const gchar *font; + const gchar *key; } winfo; static mixgtk_widget_id_t widget_ids_[] = { @@ -43,6 +45,11 @@ static mixgtk_widget_id_t widget_ids_[] = { MIXGTK_WIDGET_MIXAL, }; +static const gchar *keys_[] = { + "MIX.font", "Prompt.font", "Log.font", "MIXAL.font" +}; + + #define WIDGET_NO_ (sizeof (widget_ids_) / sizeof (widget_ids_[0])) static winfo infos_[WIDGET_NO_]; @@ -77,9 +84,14 @@ mixgtk_fontsel_init (void) gtk_widget_set_style (mixgtk_widget_factory_get (k), infos_[i].style); } - infos_[i].font = NULL; + infos_[i].key = keys_[i]; + infos_[i].font = mixgtk_config_get (keys_[i]); g_hash_table_insert (winfo_, GINT_TO_POINTER (widget_ids_[i]), (gpointer)(infos_ + i)); + if (infos_[i].font) + { + mixgtk_fontsel_set (widget_ids_[i], infos_[i].font); + } } return TRUE; } @@ -96,8 +108,7 @@ mixgtk_fontsel_set (mixgtk_widget_id_t widget, const gchar *font) { gdk_font_unref (w->style->font); w->style->font = f; - if (w->font != NULL) g_free (w->font); - w->font = g_strdup (font); + w->font = font; gtk_widget_draw (w->widget, NULL); if (widget == MIXGTK_WIDGET_MIXVM) @@ -107,6 +118,7 @@ mixgtk_fontsel_set (mixgtk_widget_id_t widget, const gchar *font) gtk_widget_draw (mixgtk_widget_factory_get (k), NULL); } } + mixgtk_config_update (w->key, w->font); } } diff --git a/mixgtk/mixgtk_mixal.c b/mixgtk/mixgtk_mixal.c index 14afacc..8cbb015 100644 --- a/mixgtk/mixgtk_mixal.c +++ b/mixgtk/mixgtk_mixal.c @@ -1,7 +1,7 @@ /* -*-c-*- -------------- mixgtk_mixal.c : * Implementation of the functions declared in mixgtk_mixal.h * ------------------------------------------------------------------ - * Last change: Time-stamp: "2001-04-22 01:02:28 jao" + * Last change: Time-stamp: "2001-04-29 22:30:43 jao" * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * @@ -26,6 +26,7 @@ #include #include "mixgtk_widgets.h" +#include "mixgtk_config.h" #include "mixgtk_mixal.h" @@ -40,12 +41,37 @@ static const char* default_colors_[3][2] = { {"white", "black"} }; +static const char* keys_[3][2] = { + {"MIXAL.bp.color.bg", "MIXAL.bp.color.fg"}, + {"MIXAL.lc.color.bg", "MIXAL.lc.color.fg"}, + {"MIXAL.pl.color.bg", "MIXAL.pl.color.fg"} +}; + +static const GdkColor * +parse_color_ (const gchar *str) +{ + static GdkColor color; + if (sscanf (str, "%hd%hd%hd", &(color.red), &(color.green), &(color.blue)) < 3) + { + g_warning ("Wrong color spec: %s\n", str); + return NULL; + } + + return &color; +} + +static const gchar * +color_to_string_ (const GdkColor *color) +{ + enum {LEN = 100}; + static gchar buffer[LEN]; + g_snprintf (buffer, LEN, "%hd %hd %hd", color->red, color->green, color->blue); + return buffer; +} static gboolean init_color_ (GdkColor *c, const gchar *name) { - if (!colormap_) - colormap_ = gtk_widget_get_colormap (GTK_WIDGET (clist_)); return (gdk_color_parse (name, c) && gdk_colormap_alloc_color (colormap_, c, FALSE, TRUE)); } @@ -62,10 +88,23 @@ mixgtk_mixal_init (mix_vm_t *vm) g_return_val_if_fail (clist_ != NULL, FALSE); /* allocate colors */ + colormap_ = gtk_widget_get_colormap (GTK_WIDGET (clist_)); for (i = 0; i < 3; ++i) for (j = 0; j < 2; ++j) - g_return_val_if_fail (init_color_ (&colors_[i][j], default_colors_[i][j]), - FALSE); + { + const gchar *ccol = mixgtk_config_get (keys_[i][j]); + const GdkColor *color = NULL; + if (ccol && (color = parse_color_ (ccol))) + { + mixgtk_mixal_set_color (i, j, color); + } + else + { + g_return_val_if_fail (init_color_ + (&colors_[i][j], default_colors_[i][j]), + FALSE); + } + } return TRUE; } @@ -82,6 +121,8 @@ mixgtk_mixal_set_color (mixal_line_t line, mixal_line_zone_t zone, colors_[line][zone].blue = color->blue; gdk_colormap_alloc_color (colormap_, &colors_[line][zone], FALSE, TRUE); mixgtk_mixal_update_bp_all (); + mixgtk_config_update (keys_[line][zone], + color_to_string_(&colors_[line][zone])); } const GdkColor * -- cgit v1.2.3