summaryrefslogtreecommitdiffhomepage
path: root/mixgtk/mixgtk_fontsel.c
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2001-04-27 22:54:00 +0000
committerJose Antonio Ortega Ruiz <jao@gnu.org>2001-04-27 22:54:00 +0000
commit75008f7cd9831b65de6e452860a6908b2019d9d1 (patch)
treea1a95da76f551bf4f4783eac3173cff0b94c0f55 /mixgtk/mixgtk_fontsel.c
parent0c1b65942150d82cd5964fc8216aa5cf831ad1fe (diff)
downloadmdk-75008f7cd9831b65de6e452860a6908b2019d9d1.tar.gz
mdk-75008f7cd9831b65de6e452860a6908b2019d9d1.tar.bz2
font customization added
Diffstat (limited to 'mixgtk/mixgtk_fontsel.c')
-rw-r--r--mixgtk/mixgtk_fontsel.c181
1 files changed, 181 insertions, 0 deletions
diff --git a/mixgtk/mixgtk_fontsel.c b/mixgtk/mixgtk_fontsel.c
new file mode 100644
index 0000000..139fe9d
--- /dev/null
+++ b/mixgtk/mixgtk_fontsel.c
@@ -0,0 +1,181 @@
+/* -*-c-*- -------------- mixgtk_fontsel.c :
+ * Implementation of the functions declared in mixgtk_fontsel.h
+ * ------------------------------------------------------------------
+ * Last change: Time-stamp: "2001-04-28 00:42:21 jao"
+ * ------------------------------------------------------------------
+ * Copyright (C) 2001 Free Software Foundation, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include <mixlib/mix.h>
+#include "mixgtk_widgets.h"
+#include "mixgtk_fontsel.h"
+
+static GtkWidget *fontsel_dialog_ = NULL;
+static mixgtk_widget_id_t widget_;
+static GHashTable *winfo_ = NULL;
+
+typedef struct winfo
+{
+ GtkWidget *widget;
+ GtkStyle *style;
+ gchar *font;
+} winfo;
+
+static mixgtk_widget_id_t widget_ids_[] = {
+ MIXGTK_WIDGET_MIXVM,
+ MIXGTK_WIDGET_PROMPT,
+ MIXGTK_WIDGET_LOG,
+ MIXGTK_WIDGET_MIXAL,
+ 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
+};
+
+#define WIDGET_NO_ (sizeof (widget_ids_) / sizeof (widget_ids_[0]))
+
+static winfo infos_[WIDGET_NO_];
+
+void
+change_font_ (mixgtk_widget_id_t widget)
+{
+ widget_ = widget;
+ gtk_widget_show (fontsel_dialog_);
+}
+
+
+/* initialise the font selection dialog */
+gboolean
+mixgtk_fontsel_init (void)
+{
+ int i;
+ fontsel_dialog_ = mixgtk_widget_factory_get (MIXGTK_WIDGET_FONTSEL_DIALOG);
+ g_return_val_if_fail (fontsel_dialog_ != NULL, FALSE);
+ winfo_ = g_hash_table_new (NULL, NULL);
+ for (i = 0; i < WIDGET_NO_; ++i)
+ {
+ infos_[i].widget = mixgtk_widget_factory_get (widget_ids_[i]);
+ g_return_val_if_fail (infos_[i].widget != NULL, FALSE);
+ infos_[i].style = gtk_style_copy
+ (gtk_widget_get_style (infos_[i].widget));
+ gtk_widget_set_style (infos_[i].widget, infos_[i].style);
+ infos_[i].font = NULL;
+ g_hash_table_insert (winfo_, GINT_TO_POINTER (widget_ids_[i]),
+ (gpointer)(infos_ + i));
+ }
+ return TRUE;
+}
+
+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)
+ {
+ GdkFont *f = gdk_font_load (font);
+ if (f != NULL)
+ {
+ gdk_font_unref (w->style->font);
+ w->style->font = f;
+ if (w->font != NULL) g_free (w->font);
+ w->font = g_strdup (font);
+ // gtk_widget_set_style (w, style);
+ gtk_widget_draw (w->widget, FALSE);
+ }
+ }
+
+ if (widget == MIXGTK_WIDGET_MIXVM)
+ {
+ int k;
+ for (k = MIXGTK_WIDGET_rA; k <= MIXGTK_WIDGET_UPTIME; ++k)
+ mixgtk_fontsel_set (k, font);
+ }
+}
+
+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)
+{
+ change_font_ (MIXGTK_WIDGET_LOG);
+}
+
+void
+on_mixal_font_activate (void)
+{
+ change_font_ (MIXGTK_WIDGET_MIXAL);
+}
+
+void
+on_prompt_font_activate (void)
+{
+ change_font_ (MIXGTK_WIDGET_PROMPT);
+}
+
+void
+on_mix_font_activate (void)
+{
+ change_font_ (MIXGTK_WIDGET_MIXVM);
+}
+
+
+void
+on_fontsel_apply_clicked (void)
+{
+ const gchar * name = gtk_font_selection_dialog_get_font_name
+ (GTK_FONT_SELECTION_DIALOG (fontsel_dialog_));
+ mixgtk_fontsel_set (widget_, name);
+}
+
+void
+on_fontsel_ok_clicked (void)
+{
+ on_fontsel_apply_clicked ();
+ gtk_widget_hide (fontsel_dialog_);
+}
+
+void
+on_fontsel_cancel_clicked (void)
+{
+ gtk_widget_hide (fontsel_dialog_);
+}
+
+