From 1f2208536e4659b79f49c0256c18f68b61ed9f7c Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Fri, 27 Apr 2001 22:54:00 +0000 Subject: font customization added --- mixgtk/.cvsignore | 1 + mixgtk/Makefile.am | 3 +- mixgtk/mixgtk.c | 13 +++- mixgtk/mixgtk.glade | 154 +++++++++++++++++++++++++++++++++++----- mixgtk/mixgtk_fontsel.c | 181 ++++++++++++++++++++++++++++++++++++++++++++++++ mixgtk/mixgtk_fontsel.h | 45 ++++++++++++ mixgtk/mixgtk_widgets.c | 10 +-- mixgtk/mixgtk_widgets.h | 12 ++-- 8 files changed, 390 insertions(+), 29 deletions(-) create mode 100644 mixgtk/mixgtk_fontsel.c create mode 100644 mixgtk/mixgtk_fontsel.h (limited to 'mixgtk') diff --git a/mixgtk/.cvsignore b/mixgtk/.cvsignore index 12ed8c2..dd99c76 100644 --- a/mixgtk/.cvsignore +++ b/mixgtk/.cvsignore @@ -2,6 +2,7 @@ Makefile Makefile.in gmixvm +gmixvm.core hello.mix mixgtk paper.dev diff --git a/mixgtk/Makefile.am b/mixgtk/Makefile.am index adf036e..c0a3788 100644 --- a/mixgtk/Makefile.am +++ b/mixgtk/Makefile.am @@ -26,7 +26,8 @@ gmixvm_SOURCES = mixgtk.c mixgtk_gen_handlers.h mixgtk_gen_handlers.c \ mixgtk_mixvm.h mixgtk_mixvm.c \ mixgtk_mixal.h mixgtk_mixal.c \ mixgtk_input.h mixgtk_input.c \ - mixgtk_colorsel.h mixgtk_colorsel.c + mixgtk_colorsel.h mixgtk_colorsel.c \ + mixgtk_fontsel.h mixgtk_fontsel.c endif diff --git a/mixgtk/mixgtk.c b/mixgtk/mixgtk.c index 2e2b44c..127780b 100644 --- a/mixgtk/mixgtk.c +++ b/mixgtk/mixgtk.c @@ -1,7 +1,7 @@ /* -*-c-*- -------------- mixgtk.c : * Main function of the mix gtk front-end * ------------------------------------------------------------------ - * Last change: Time-stamp: "2001-04-22 01:00:42 jao" + * Last change: Time-stamp: "2001-04-24 00:52:32 jao" * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * @@ -31,13 +31,14 @@ #include "mixgtk_mixal.h" #include "mixgtk_input.h" #include "mixgtk_colorsel.h" +#include "mixgtk_fontsel.h" int main(int argc, char *argv[]) { mix_vm_t *vm; - gtk_init(&argc, &argv); + gtk_init (&argc, &argv); mix_init_lib (); @@ -71,7 +72,7 @@ main(int argc, char *argv[]) return EXIT_FAILURE; } - if (!mixgtk_mixal_init (vm) || !mixgtk_colorsel_init ()) + if (!mixgtk_mixal_init (vm)) { g_error ("Unable to initialise application (mixal widgets)\n"); return EXIT_FAILURE; @@ -82,6 +83,12 @@ main(int argc, char *argv[]) g_error ("Unable to initialise application (word input widgets)\n"); return EXIT_FAILURE; } + + if (!mixgtk_fontsel_init () || !mixgtk_colorsel_init ()) + { + g_error ("Unable to initialise application (customization widgets)\n"); + return EXIT_FAILURE; + } gtk_main(); diff --git a/mixgtk/mixgtk.glade b/mixgtk/mixgtk.glade index 665c8ec..eb3af1e 100644 --- a/mixgtk/mixgtk.glade +++ b/mixgtk/mixgtk.glade @@ -187,13 +187,61 @@ GtkMenuItem fonts1 - - activate - on_fonts1_activate - Wed, 11 Apr 2001 23:15:11 GMT - - + False + + + GtkMenu + fonts1_menu + + + GtkMenuItem + mix + + activate + on_mix_font_activate + Wed, 25 Apr 2001 01:55:53 GMT + + + False + + + + GtkMenuItem + mixal + + activate + on_mixal_font_activate + Wed, 25 Apr 2001 01:55:53 GMT + + + False + + + + GtkMenuItem + command_prompt + + activate + on_prompt_font_activate + Wed, 25 Apr 2001 01:55:53 GMT + + + False + + + + GtkMenuItem + command_log + + activate + on_log_font_activate + Wed, 25 Apr 2001 01:55:53 GMT + + + False + + @@ -579,15 +627,6 @@ 263 - - GtkHSeparator - hseparator3 - 6 - 1 - 627 - 16 - - GtkVSeparator vseparator3 @@ -943,6 +982,15 @@ + + + GtkHSeparator + hseparator3 + 6 + 1 + 627 + 16 + @@ -1979,7 +2027,7 @@ GtkDrawingArea bpbg_area 90 - 93 + 94 75 15 @@ -2082,4 +2130,78 @@ + + GtkFontSelectionDialog + fontsel_dialog + 4 + False + + delete_event + gtk_widget_hide + Thu, 26 Apr 2001 21:14:34 GMT + + + destroy_event + gtk_widget_hide + Thu, 26 Apr 2001 21:15:02 GMT + + + destroy + gtk_widget_hide + Thu, 26 Apr 2001 21:15:13 GMT + + Select Font + GTK_WINDOW_DIALOG + GTK_WIN_POS_NONE + False + False + True + True + + + GtkButton + FontSel:ok_button + ok_button1 + True + True + + clicked + on_fontsel_ok_clicked + Thu, 26 Apr 2001 21:40:53 GMT + + + GTK_RELIEF_NORMAL + + + + GtkButton + FontSel:apply_button + apply_button1 + True + True + + clicked + on_fontsel_apply_clicked + Thu, 26 Apr 2001 21:41:12 GMT + + + GTK_RELIEF_NORMAL + + + + GtkButton + FontSel:cancel_button + cancel_button1 + True + True + + clicked + on_fontsel_cancel_clicked + Thu, 26 Apr 2001 21:41:33 GMT + + + GTK_RELIEF_NORMAL + + + 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 +#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_); +} + + diff --git a/mixgtk/mixgtk_fontsel.h b/mixgtk/mixgtk_fontsel.h new file mode 100644 index 0000000..5b9b1f6 --- /dev/null +++ b/mixgtk/mixgtk_fontsel.h @@ -0,0 +1,45 @@ +/* -*-c-*- ---------------- mixgtk_fontsel.h : + * Functions for handling font selection. + * ------------------------------------------------------------------ + * Last change: Time-stamp: <2001-04-28 00:42:39 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. + * + */ + + +#ifndef MIXGTK_FONTSEL_H +#define MIXGTK_FONTSEL_H + +#include +#include "mixgtk_widgets.h" + +/* initialise the font selection dialog */ +extern gboolean +mixgtk_fontsel_init (void); + +/* set a widget's font */ +extern void +mixgtk_fontsel_set (mixgtk_widget_id_t widget, const gchar *font); + +/* get a widget's font */ +extern const gchar * +mixgtk_fontsel_get (mixgtk_widget_id_t widget); + + +#endif /* MIXGTK_FONTSEL_H */ + diff --git a/mixgtk/mixgtk_widgets.c b/mixgtk/mixgtk_widgets.c index c27b707..a26d886 100644 --- a/mixgtk/mixgtk_widgets.c +++ b/mixgtk/mixgtk_widgets.c @@ -1,7 +1,7 @@ /* -*-c-*- -------------- mixgtk_widgets.c : * Implementation of the functions declared in mixgtk_widgets.h * ------------------------------------------------------------------ - * Last change: Time-stamp: "2001-04-22 00:01:30 jao" + * Last change: Time-stamp: "2001-04-27 23:32:32 jao" * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * @@ -38,6 +38,8 @@ static const gchar *names_[] = { "about_dialog", "goto_dialog", "color_dialog", + "fontsel_dialog", + "mixvm_widget", "command_prompt", "command_log", "mixal_clist", @@ -55,12 +57,12 @@ static const gchar *names_[] = { "greater_radio", "over_toggle", "memory_cells", - "memory_scroll", - "devices_notebook", - "loc_entry", "elapsed_label", "program_label", "uptime_label", + "memory_scroll", + "devices_notebook", + "loc_entry", NULL }; diff --git a/mixgtk/mixgtk_widgets.h b/mixgtk/mixgtk_widgets.h index 00147fc..461e1bf 100644 --- a/mixgtk/mixgtk_widgets.h +++ b/mixgtk/mixgtk_widgets.h @@ -1,7 +1,7 @@ /* -*-c-*- ---------------- mixgtk_widgets.h : * glade-based factory of mixvm widgets * ------------------------------------------------------------------ - * Last change: Time-stamp: <2001-04-22 00:01:13 jao> + * Last change: Time-stamp: <2001-04-27 23:32:16 jao> * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * @@ -35,7 +35,9 @@ typedef enum { MIXGTK_WIDGET_WORD_DIALOG, /* input dialog for a mix word */ MIXGTK_WIDGET_ABOUT_DIALOG, MIXGTK_WIDGET_GOTO_DIALOG, - MIXGTK_WIDGET_COLORSEL_DIALOG, /* color selection dialog */ + MIXGTK_WIDGET_COLORSEL_DIALOG, /* color customization dialog */ + MIXGTK_WIDGET_FONTSEL_DIALOG, /* font selection dialog */ + MIXGTK_WIDGET_MIXVM, /* virtual machine */ MIXGTK_WIDGET_PROMPT, /* command prompt */ MIXGTK_WIDGET_LOG, /* command output */ MIXGTK_WIDGET_MIXAL, /* mixal source file */ @@ -53,12 +55,12 @@ typedef enum { MIXGTK_WIDGET_CMP_G, MIXGTK_WIDGET_OVER, MIXGTK_WIDGET_CELLS, - MIXGTK_WIDGET_CELLS_SCROLL, - MIXGTK_WIDGET_DEVICE, - MIXGTK_WIDGET_LOC, MIXGTK_WIDGET_LAPTIME, MIXGTK_WIDGET_PROGTIME, MIXGTK_WIDGET_UPTIME, + MIXGTK_WIDGET_CELLS_SCROLL, + MIXGTK_WIDGET_DEVICE, + MIXGTK_WIDGET_LOC, MIXGTK_WIDGET_NONE } mixgtk_widget_id_t; -- cgit v1.2.3