summaryrefslogtreecommitdiffhomepage
path: root/mixgtk/mixgtk_fontsel.c
diff options
context:
space:
mode:
Diffstat (limited to 'mixgtk/mixgtk_fontsel.c')
-rw-r--r--mixgtk/mixgtk_fontsel.c240
1 files changed, 49 insertions, 191 deletions
diff --git a/mixgtk/mixgtk_fontsel.c b/mixgtk/mixgtk_fontsel.c
index 50bcceb..59849b1 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
* ------------------------------------------------------------------
- * $Id: mixgtk_fontsel.c,v 1.15 2004/06/23 10:50:10 jao Exp $
+ * $Id: mixgtk_fontsel.c,v 1.16 2004/06/24 01:40:47 jao Exp $
* ------------------------------------------------------------------
* Copyright (C) 2001, 2004 Free Software Foundation, Inc.
*
@@ -26,223 +26,81 @@
#include "mixgtk_config.h"
#include "mixgtk_fontsel.h"
-static GtkWidget *fontsel_dialog_ = NULL;
-static mixgtk_widget_id_t widget_;
-static GHashTable *winfo_ = NULL;
+static GtkFontSelectionDialog *fontsel_dialog_ = NULL;
-typedef struct winfo
-{
- GtkWidget *widget;
- const gchar *font;
- const gchar *key;
-} winfo;
-
-static mixgtk_widget_id_t widget_ids_[] = {
- MIXGTK_WIDGET_MIXVM,
- MIXGTK_WIDGET_PROMPT,
- MIXGTK_WIDGET_LOG,
- MIXGTK_WIDGET_MIXAL,
- MIXGTK_WIDGET_DEVICE
-};
-
-static mixgtk_dialog_id_t dialog_ids_no_split_[] = {
- MIXGTK_MAIN,
- MIXGTK_MAIN,
- MIXGTK_MAIN,
- MIXGTK_MAIN,
- MIXGTK_MAIN,
-};
-
-static mixgtk_dialog_id_t dialog_ids_split_[] = {
- MIXGTK_MIXVM_DIALOG,
- MIXGTK_MAIN,
- MIXGTK_MAIN,
- MIXGTK_MIXAL_DIALOG,
- MIXGTK_DEVICES_DIALOG
-};
-
-static mixgtk_widget_id_t mixvm_children_[] = {
- MIXGTK_WIDGET_rA,
- MIXGTK_WIDGET_rX,
- MIXGTK_WIDGET_rJ,
- MIXGTK_WIDGET_rI1,
- MIXGTK_WIDGET_rI2,
- MIXGTK_WIDGET_rI3,
- MIXGTK_WIDGET_rI4,
- MIXGTK_WIDGET_rI5,
- MIXGTK_WIDGET_rI6,
- MIXGTK_WIDGET_CMP_L,
- MIXGTK_WIDGET_CMP_E,
- MIXGTK_WIDGET_CMP_G,
- MIXGTK_WIDGET_OVER,
- MIXGTK_WIDGET_CELLS,
- MIXGTK_WIDGET_LAPTIME,
- MIXGTK_WIDGET_PROGTIME,
- MIXGTK_WIDGET_UPTIME,
- MIXGTK_WIDGET_LOC
+static const gchar *keys_[MIX_FONT_NO] = {
+ "MIX.font", "Prompt.font", "Log.font", "MIXAL.font", "Devices.font"
};
-static const int CHILDREN_NO_ =
-(sizeof (mixvm_children_) / sizeof (mixvm_children_[0]));
-
-static mixgtk_dialog_id_t *dialog_ids_ = NULL;
-
-static const gchar *keys_[] = {
- "MIX.font", "Prompt.font", "Log.font", "MIXAL.font", "Device.font"
-};
-
-
-
-#define WIDGET_NO_ (sizeof (widget_ids_) / sizeof (widget_ids_[0]))
-
-static winfo infos_[WIDGET_NO_];
/* initialise the font selection dialog */
static void
init_fontsel_ (void)
{
- fontsel_dialog_ = mixgtk_widget_factory_get_dialog (MIXGTK_FONTSEL_DIALOG);
+ fontsel_dialog_ =
+ GTK_FONT_SELECTION_DIALOG
+ (mixgtk_widget_factory_get_dialog (MIXGTK_FONTSEL_DIALOG));
g_assert (fontsel_dialog_ != NULL);
}
void
-change_font_ (mixgtk_widget_id_t widget)
+mixgtk_fontsel_set_font (mixgtk_font_t f, GtkWidget *w)
{
- winfo *info;
- if (!fontsel_dialog_) init_fontsel_ ();
- info = (winfo *) g_hash_table_lookup (winfo_, GINT_TO_POINTER (widget));
- g_assert (info);
- widget_ = widget;
- if (info->font)
- gtk_font_selection_dialog_set_font_name
- (GTK_FONT_SELECTION_DIALOG (fontsel_dialog_), info->font);
-
- gtk_widget_show (fontsel_dialog_);
-
-}
-
-void
-mixgtk_fontsel_load_defaults (void)
-{
-
- int i;
const gchar *font;
- gboolean split = mixgtk_config_is_split ();
+ PangoFontDescription *font_desc;
- fontsel_dialog_ = NULL;
+ if (f >= MIX_FONT_NO || w == NULL) return;
- if (winfo_) g_hash_table_destroy (winfo_);
- winfo_ = g_hash_table_new (NULL, NULL);
- dialog_ids_ = split? dialog_ids_split_ : dialog_ids_no_split_;
- for (i = 0; i < WIDGET_NO_; ++i)
+ font = mixgtk_config_get (keys_[f]);
+ if (!font)
{
- infos_[i].widget =
- mixgtk_widget_factory_get (dialog_ids_[i], widget_ids_[i]);
- g_assert (infos_[i].widget != NULL);
- infos_[i].key = keys_[i];
- g_hash_table_insert (winfo_, GINT_TO_POINTER (widget_ids_[i]),
- (gpointer)(infos_ + i));
-
- infos_[i].font = NULL;
- font = mixgtk_config_get (keys_[i]);
- mixgtk_fontsel_set (widget_ids_[i], font? font : "Monospace");
+ mixgtk_config_update (keys_[f], "Monospace");
+ font = mixgtk_config_get (keys_[f]);
+ g_assert (font);
}
-}
-void
-mixgtk_fontsel_set (mixgtk_widget_id_t widget, const gchar *font)
-{
- winfo *w = (winfo *)
- g_hash_table_lookup (winfo_, GINT_TO_POINTER (widget));
- if (w != NULL && font != NULL)
+ font_desc = pango_font_description_from_string (font);
+
+ if (font_desc)
{
- PangoFontDescription *font_desc =
- pango_font_description_from_string (font);
- if (font_desc != NULL)
- {
- gtk_widget_modify_font (w->widget, font_desc);
-
- if (widget == MIXGTK_WIDGET_MIXVM)
- {
- int k;
- for (k = 0; k < CHILDREN_NO_; ++k)
- {
- GtkWidget *child =
- mixgtk_widget_factory_get (MIXGTK_MIXVM_DIALOG,
- mixvm_children_[k]);
- gtk_widget_modify_font (child, font_desc);
- }
- }
- w->font = font;
- mixgtk_config_update (w->key, w->font);
- pango_font_description_free (font_desc);
- }
- else
- mixgtk_config_remove (w->key);
+ gtk_widget_modify_font (w, font_desc);
+ gtk_widget_queue_draw (w);
+ pango_font_description_free (font_desc);
}
-}
+ else
+ mixgtk_config_remove (keys_[f]);
-const gchar *
-mixgtk_fontsel_get (mixgtk_widget_id_t widget)
-{
- const gchar *result = NULL;
- winfo *w = (winfo *)
- g_hash_table_lookup (winfo_, GINT_TO_POINTER (widget));
- if (w != NULL) result = w->font;
- return result;
}
-/* callbacks */
-void
-on_log_font_activate (void)
+extern gboolean
+mixgtk_fontsel_query_font (mixgtk_font_t f, GtkWidget **w, size_t no)
{
- change_font_ (MIXGTK_WIDGET_LOG);
-}
-
-void
-on_mixal_font_activate (void)
-{
- change_font_ (MIXGTK_WIDGET_MIXAL);
-}
+ gint result = GTK_RESPONSE_APPLY;
+ const gchar *current;
+ gboolean ret = FALSE;
-void
-on_prompt_font_activate (void)
-{
- change_font_ (MIXGTK_WIDGET_PROMPT);
-}
-
-void
-on_mix_font_activate (void)
-{
- change_font_ (MIXGTK_WIDGET_MIXVM);
-}
-
-void
-on_devices_font_activate (void)
-{
- change_font_ (MIXGTK_WIDGET_DEVICE);
-}
-
-void
-on_fontsel_apply_clicked (void)
-{
- gchar * name = gtk_font_selection_dialog_get_font_name
- (GTK_FONT_SELECTION_DIALOG (fontsel_dialog_));
- mixgtk_fontsel_set (widget_, name);
- g_free (name);
-}
+ if (f >= MIX_FONT_NO) return FALSE;
+ if (!fontsel_dialog_) init_fontsel_ ();
-void
-on_fontsel_ok_clicked (void)
-{
- on_fontsel_apply_clicked ();
- gtk_widget_hide (fontsel_dialog_);
-}
+ current = mixgtk_config_get (keys_[f]);
+ gtk_font_selection_dialog_set_font_name (fontsel_dialog_,
+ current? current : "Monospace");
-void
-on_fontsel_cancel_clicked (void)
-{
- gtk_widget_hide (fontsel_dialog_);
+ while (result == GTK_RESPONSE_APPLY)
+ {
+ result = gtk_dialog_run (GTK_DIALOG (fontsel_dialog_));
+ if (result != GTK_RESPONSE_CANCEL)
+ {
+ gint k;
+ mixgtk_config_update
+ (keys_[f],
+ gtk_font_selection_dialog_get_font_name (fontsel_dialog_));
+ for (k = 0; k < no; ++k)
+ mixgtk_fontsel_set_font (f, w[k]);
+ ret = TRUE;
+ }
+ }
+ gtk_widget_hide (GTK_WIDGET (fontsel_dialog_));
+ return ret;
}
-