From 300160e73da486946ae513f1d039dcd7b85ff17c Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Mon, 20 Mar 2006 22:46:46 +0000 Subject: Version 1.2.1 imported git-archimport-id: mdk@sv.gnu.org/mdk--devel--1--patch-1 --- mixgtk/Makefile.am | 47 + mixgtk/gmixvm.c | 124 ++ mixgtk/mixgtk.c | 79 + mixgtk/mixgtk.glade | 3913 ++++++++++++++++++++++++++++++++++++++++ mixgtk/mixgtk.gladep | 9 + mixgtk/mixgtk.h | 49 + mixgtk/mixgtk_cmd_dispatcher.c | 547 ++++++ mixgtk/mixgtk_cmd_dispatcher.h | 61 + mixgtk/mixgtk_config.c | 113 ++ mixgtk/mixgtk_config.h | 70 + mixgtk/mixgtk_device.c | 625 +++++++ mixgtk/mixgtk_device.h | 45 + mixgtk/mixgtk_fontsel.c | 142 ++ mixgtk/mixgtk_fontsel.h | 51 + mixgtk/mixgtk_gen_handlers.c | 165 ++ mixgtk/mixgtk_gen_handlers.h | 62 + mixgtk/mixgtk_input.c | 233 +++ mixgtk/mixgtk_input.h | 49 + mixgtk/mixgtk_mixal.c | 580 ++++++ mixgtk/mixgtk_mixal.h | 66 + mixgtk/mixgtk_mixvm.c | 529 ++++++ mixgtk/mixgtk_mixvm.h | 72 + mixgtk/mixgtk_widgets.c | 153 ++ mixgtk/mixgtk_widgets.h | 102 ++ mixgtk/mixgtk_wm.c | 573 ++++++ mixgtk/mixgtk_wm.h | 46 + 26 files changed, 8505 insertions(+) create mode 100644 mixgtk/Makefile.am create mode 100644 mixgtk/gmixvm.c create mode 100644 mixgtk/mixgtk.c create mode 100644 mixgtk/mixgtk.glade create mode 100644 mixgtk/mixgtk.gladep create mode 100644 mixgtk/mixgtk.h create mode 100644 mixgtk/mixgtk_cmd_dispatcher.c create mode 100644 mixgtk/mixgtk_cmd_dispatcher.h create mode 100644 mixgtk/mixgtk_config.c create mode 100644 mixgtk/mixgtk_config.h create mode 100644 mixgtk/mixgtk_device.c create mode 100644 mixgtk/mixgtk_device.h create mode 100644 mixgtk/mixgtk_fontsel.c create mode 100644 mixgtk/mixgtk_fontsel.h create mode 100644 mixgtk/mixgtk_gen_handlers.c create mode 100644 mixgtk/mixgtk_gen_handlers.h create mode 100644 mixgtk/mixgtk_input.c create mode 100644 mixgtk/mixgtk_input.h create mode 100644 mixgtk/mixgtk_mixal.c create mode 100644 mixgtk/mixgtk_mixal.h create mode 100644 mixgtk/mixgtk_mixvm.c create mode 100644 mixgtk/mixgtk_mixvm.h create mode 100644 mixgtk/mixgtk_widgets.c create mode 100644 mixgtk/mixgtk_widgets.h create mode 100644 mixgtk/mixgtk_wm.c create mode 100644 mixgtk/mixgtk_wm.h (limited to 'mixgtk') diff --git a/mixgtk/Makefile.am b/mixgtk/Makefile.am new file mode 100644 index 0000000..60adf8d --- /dev/null +++ b/mixgtk/Makefile.am @@ -0,0 +1,47 @@ +## Process this file with automake to produce Makefile.in + +# Copyright (C) 2001, 2004 Free Software Foundation, Inc. +# +# This file is free software; as a special exception the author gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +# $Id: Makefile.am,v 1.19 2005/09/18 21:49:40 jao Exp $ + +EXTRA_DIST = mixgtk.glade + +if MAKE_GUILE +GUILED = -DMAKE_GUILE +else +GUILED = +endif + +if MAKE_GUI + +pkgdata_DATA = mixgtk.glade + +INCLUDES = -I$(includedir) -I$(top_srcdir) \ + -DGLADE_FILE=\""$(pkgdatadir)/mixgtk.glade"\"\ + -DLOCAL_GLADE_FILE=\""$(srcdir)/mixgtk.glade"\"\ + $(GUILED) +LDADD = $(top_builddir)/mixlib/libmix.a $(top_builddir)/lib/libreplace.a\ + $(top_builddir)/mixguile/libmixguile.a $(INTLLIBS) + +AM_LDFLAGS = -Wl,--export-dynamic +bin_PROGRAMS = gmixvm +gmixvm_SOURCES = gmixvm.c mixgtk.h mixgtk.c \ + mixgtk_config.h mixgtk_config.c \ + mixgtk_gen_handlers.h mixgtk_gen_handlers.c \ + mixgtk_cmd_dispatcher.h mixgtk_cmd_dispatcher.c \ + mixgtk_widgets.h mixgtk_widgets.c \ + mixgtk_device.h mixgtk_device.c \ + mixgtk_mixvm.h mixgtk_mixvm.c \ + mixgtk_mixal.h mixgtk_mixal.c \ + mixgtk_input.h mixgtk_input.c \ + mixgtk_fontsel.h mixgtk_fontsel.c \ + mixgtk_wm.h mixgtk_wm.c +endif diff --git a/mixgtk/gmixvm.c b/mixgtk/gmixvm.c new file mode 100644 index 0000000..150c891 --- /dev/null +++ b/mixgtk/gmixvm.c @@ -0,0 +1,124 @@ +/* -*-c-*- -------------- gmixvm.c : + * Main function of the mix gtk front-end + * ------------------------------------------------------------------ + * $Id: gmixvm.c,v 1.6 2005/09/20 19:43:14 jao Exp $ + * ------------------------------------------------------------------ + * Copyright (C) 2001, 2002 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include +#include +#include "mixgtk.h" + +static gboolean initfile_ = TRUE; + +#ifdef MAKE_GUILE +# include +# include "mixgtk_cmd_dispatcher.h" +static void +inner_main_ (int argc, char *argv[]) +{ + mixgtk_init (argc, argv); + mixguile_set_cmd_dispatcher (mixgtk_cmd_dispatcher_get_mix_dispatcher ()); + mixguile_load_bootstrap (initfile_); + mixgtk_main (); + mixgtk_release (); +} +#endif + +#ifdef HAVE_GETOPT_LONG +# include +#else +# include +#endif /* HAVE_GETOPT_LONG */ + +enum { + VER_OPT = 'v', + NOINIT_OPT = 'q', + HELP_OPT = 'h', + USAGE_OPT = 'u' +}; + +static const char *options_ = "vqhu"; + +static struct option long_options_[] = +{ + {"version", no_argument, 0, VER_OPT}, + {"help", no_argument, 0, HELP_OPT}, + {"usage", no_argument, 0, USAGE_OPT}, + {"noinit", no_argument, 0, NOINIT_OPT}, + {0, 0, 0, 0} +}; + +static void print_usage_ (const gchar *prog) +{ + static const char *usage_ = + "Usage: %s [-vhuq] [--version] [--help] [--usage] [--noinit]\n"; + fprintf (stderr, usage_, prog); +} + +int +main(int argc, char *argv[]) +{ + int c; + + const char *prog_name = argv[0]; + + setlocale (LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); + + while (1) + { + c = getopt_long (argc, argv, options_, long_options_, (int*)0); + + /* Detect the end of the options. */ + if (c == -1) + break; + + switch (c) + { + case VER_OPT: + mix_print_license (_("gmixvm, GTK MIX virtual machine")); + return EXIT_SUCCESS; + case NOINIT_OPT: + initfile_ = FALSE; + break; + case HELP_OPT: + case USAGE_OPT: + print_usage_ (prog_name); + return EXIT_SUCCESS; + case '?': + print_usage_ (prog_name); + return EXIT_FAILURE; + default: + g_assert_not_reached (); + break; + } + } + +#ifdef MAKE_GUILE + mixguile_enter (argc, argv, inner_main_); +#else + if (!mixgtk_init (argc, argv)) return EXIT_FAILURE; + mixgtk_main (); + mixgtk_release (); +#endif + + return EXIT_SUCCESS; +} diff --git a/mixgtk/mixgtk.c b/mixgtk/mixgtk.c new file mode 100644 index 0000000..eddb528 --- /dev/null +++ b/mixgtk/mixgtk.c @@ -0,0 +1,79 @@ +/* -*-c-*- -------------- mixgtk.c : + * Main functions of the mix gtk front-end + * ------------------------------------------------------------------ + * $Id: mixgtk.c,v 1.19 2005/09/20 19:43:14 jao Exp $ + * ------------------------------------------------------------------ + * Copyright (C) 2001, 2002, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include +#include + +#include "mixgtk_widgets.h" + +#include "mixgtk_cmd_dispatcher.h" +#include "mixgtk_input.h" +#include "mixgtk_config.h" +#include "mixgtk_wm.h" +#include "mixgtk.h" + +/* initialise the app */ +gboolean +mixgtk_init (int argc, char *argv[]) +{ + mix_init_lib (); + + gtk_init (&argc, &argv); + + if (!mixgtk_config_load ()) + { + g_error (_("Unable to load gmixvm configuration")); + } + + if (!mixgtk_widget_factory_init ()) + { + g_error (_("Unable to initialise application: missing glade file")); + return FALSE; + } + + if (!mixgtk_wm_init ()) + { + g_error (_("Unable to initialise application\n")); + return FALSE; + } + + mixgtk_input_init (); + + return TRUE; +} + +/* main loop */ +void +mixgtk_main (void) +{ + gtk_main (); +} + +/* clean up */ +void +mixgtk_release (void) +{ + if (mixgtk_config_is_autosave ()) mixgtk_config_save (); + mix_vm_cmd_dispatcher_delete (mixgtk_cmd_dispatcher_get_mix_dispatcher ()); + mix_release_lib (); +} diff --git a/mixgtk/mixgtk.glade b/mixgtk/mixgtk.glade new file mode 100644 index 0000000..f16f441 --- /dev/null +++ b/mixgtk/mixgtk.glade @@ -0,0 +1,3913 @@ + + + + + + + gmixvm + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + 650 + 550 + True + False + gmixvm-main + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST + + + + 2 + True + False + 2 + + + + True + + + + True + _File + True + + + + + + + True + Load a MIX file + _Load... + True + + + + + + True + gtk-open + 1 + 0.5 + 0.5 + 0 + 0 + + + + + + + + True + Edit a MIXAL source file + _Edit... + True + + + + + + True + gtk-justify-fill + 1 + 0.5 + 0.5 + 0 + 0 + + + + + + + + True + Compile a MIXAL source file + _Compile... + True + + + + + + True + gtk-execute + 1 + 0.5 + 0.5 + 0 + 0 + + + + + + + + True + + + + + + True + Exit application + E_xit + True + + + + + + True + gtk-quit + 1 + 0.5 + 0.5 + 0 + 0 + + + + + + + + + + + + True + De_bug + True + + + + + + + True + Run program + _Run + True + + + + + + True + gtk-go-forward + 1 + 0.5 + 0.5 + 0 + 0 + + + + + + + + True + Execute next instruction + _Next + True + + + + + + True + gtk-goto-last + 1 + 0.5 + 0.5 + 0 + 0 + + + + + + + + True + Clear all set breakpoints + _Clear breakpoints + True + + + + + + True + gtk-clear + 1 + 0.5 + 0.5 + 0 + 0 + + + + + + + + True + Show the symbol table + _Symbols... + True + + + + + + True + gtk-index + 1 + 0.5 + 0.5 + 0 + 0 + + + + + + + + + + + + True + Vie_w + True + + + + + + + True + _Toolbars + True + False + + + + + + True + _Detached windows + True + + + + True + gtk-dnd-multiple + 1 + 0.5 + 0.5 + 0 + 0 + + + + + + + + + True + _Virtual machine + True + False + + + + + + True + _Source + True + False + + + + + + True + _Devices + True + False + + + + + + + + + + + + + + True + S_ettings + True + + + + + + + True + Change _font + True + + + + True + gtk-select-font + 1 + 0.5 + 0.5 + 0 + 0 + + + + + + + + + True + _Virtual machine + True + + + + + + + True + _Source + True + + + + + + + True + Command _prompt + True + + + + + + + True + Command l_og + True + + + + + + + True + _Devices + True + + + + + + + True + Symbol _list + True + + + + + + + True + + + + + + True + Change all fonts at once + _All + True + + + + + + + + + + + True + Change format of binary devices output + _Device output... + True + + + + + True + gtk-zoom-100 + 1 + 0.5 + 0.5 + 0 + 0 + + + + + + + + True + De_vices dir... + True + + + + + True + gtk-home + 1 + 0.5 + 0.5 + 0 + 0 + + + + + + + + True + E_xternal programs... + True + + + + + True + gtk-preferences + 1 + 0.5 + 0.5 + 0 + 0 + + + + + + + + True + + + + + + True + Save current settings + _Save + True + + + + + True + gtk-save + 1 + 0.5 + 0.5 + 0 + 0 + + + + + + + + True + Toogle save settings on exit + Save on _exit + True + False + + + + + + + + + + + True + _Help + True + + + + + + + True + _About... + True + + + + + True + gtk-help + 1 + 0.5 + 0.5 + 0 + 0 + + + + + + + + + + + 0 + False + True + + + + + + True + GTK_SHADOW_OUT + GTK_POS_LEFT + GTK_POS_TOP + + + + True + GTK_ORIENTATION_HORIZONTAL + GTK_TOOLBAR_ICONS + True + True + + + + True + Load MIX program + Open + True + gtk-open + True + True + True + + + + False + True + + + + + + True + Compile MIXAL source + Compile + True + gtk-execute + True + True + True + + + + False + True + + + + + + True + Edit MIXAL source + Edit + True + gtk-justify-fill + True + True + True + + + + False + True + + + + + + True + Run + Run + True + gtk-go-forward + True + True + True + + + + False + True + + + + + + True + Next + Next + True + gtk-goto-last + True + True + True + + + + False + True + + + + + + True + Clear breakpoints + Clear + True + gtk-clear + True + True + True + + + + False + True + + + + + + True + Symbol table + Symbols + True + gtk-index + True + True + True + + + + False + True + + + + + + True + True + True + True + + + False + False + + + + + + True + Device directory + Devdir + True + gtk-home + True + True + False + + + + False + True + + + + + + True + Output format + Format + True + gtk-zoom-100 + True + True + False + + + + False + True + + + + + + True + External programs + Programs + True + gtk-properties + True + True + False + + + + False + True + + + + + + True + True + True + True + + + False + False + + + + + + True + Detach window + Detach + True + gtk-dnd-multiple + True + True + False + + + + False + True + + + + + + True + Attach all windows + + True + gtk-dnd + True + True + True + + + + False + True + + + + + + + 3 + False + False + + + + + + True + True + 1 + + + + True + True + True + True + GTK_POS_TOP + False + False + + + False + True + + + + + + True + False + 0 + + + + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + False + False + True + GTK_JUSTIFY_LEFT + GTK_WRAP_WORD + True + 0 + 0 + 0 + 3 + 4 + 0 + + + + + + 0 + True + True + + + + + + True + Enter MIXVM command here + True + True + True + True + 0 + + True + * + False + + + + + 0 + False + False + + + + + True + True + + + + + 0 + True + True + + + + + + True + True + + + 0 + False + False + + + + + + + + Enter value + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + True + False + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + + + + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + + True + True + True + gtk-clear + True + GTK_RELIEF_NORMAL + False + 0 + + + + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -5 + + + + + + 0 + False + False + GTK_PACK_END + + + + + + 5 + True + + + + 0 + 0 + True + True + True + GDK_KEY_PRESS_MASK + True + True + 0 + 0 + True + * + False + 28 + + + + 88 + 64 + + + + + + 0 + 0 + True + True + GDK_KEY_PRESS_MASK + True + True + 2 + 0 + True + * + False + 3 + + + + 144 + 32 + + + + + + 0 + 0 + True + True + GDK_BUTTON_PRESS_MASK + True + True + 2 + 0 + True + * + False + 3 + + + + 176 + 32 + + + + + + 0 + 0 + True + True + GDK_KEY_PRESS_MASK + True + True + 2 + 0 + True + * + False + 3 + + + + 208 + 32 + + + + + + 0 + 0 + True + True + GDK_KEY_PRESS_MASK + True + True + 2 + 0 + True + * + False + 3 + + + + 238 + 32 + + + + + + 0 + 0 + True + True + GDK_KEY_PRESS_MASK + True + True + 2 + 0 + True + * + False + 3 + + + + 112 + 32 + + + + + + 0 + 0 + True + True + GDK_KEY_PRESS_MASK + True + True + 1 + + + True + * + False + 2 + + + + 88 + 32 + + + + + + 0 + 0 + True + Decimal + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 0 + + + 14 + 68 + + + + + + 0 + 0 + True + Bytes + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 0 + + + 15 + 36 + + + + + + 0 + 0 + True + Enter value + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 0 + + + 112 + 8 + + + + + 0 + True + True + + + + + + + + MDK + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_CENTER + True + 250 + 150 + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST + + + + + + + True + 250 + 150 + 0 0 250 0 225 250 + 0 0 150 0 135 150 + + + + 0 + 0 + True + GNU MIX Development Kit + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 0 + + + 56 + 24 + + + + + + 52 + 16 + True + label223 + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 0 + + + 96 + 48 + + + + + + 0 + 0 + True + Copyright (C) 2001, 2002, 2003 , 2004 +Free Software Foundation, Inc. + +Please, send bug reports to +bug-mdk@gnu.org + False + False + GTK_JUSTIFY_CENTER + True + False + 0.5 + 0.5 + 0 + 0 + + + 24 + 80 + + + + + + + + Go to memory cell + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + True + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + + + + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + True + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + 12 + True + False + 0 + + + + True + Go to address: + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + True + True + + + + + + True + True + True + True + True + 0 + + True + * + True + + + 10 + False + False + + + + + 0 + False + False + + + + + + + + 4 + Select Font + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + True + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + + + + + + + True + True + True + GTK_RELIEF_NORMAL + True + + + + + + True + True + True + GTK_RELIEF_NORMAL + True + + + + + + True + True + True + GTK_RELIEF_NORMAL + True + + + + + + 4 + True + abcdefghijk ABCDEFGHIJK + + + 0 + True + True + + + + + + Device output format + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + True + 320 + 140 + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + + + + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + True + True + True + gtk-apply + True + GTK_RELIEF_NORMAL + True + -10 + + + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + True + + + + 0 + 0 + True + Set all devices to current format + True + S_et all + True + GTK_RELIEF_NORMAL + True + + + + 233 + 31 + + + + + + 0 + 0 + True + Device + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 0 + + + 24 + 10 + + + + + + 0 + 0 + True + Format + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 0 + + + 24 + 38 + + + + + + 183 + 25 + True + tape0 +tape1 +tape2 +tape3 +tape4 +tape5 +tape6 +tape7 +disk0 +disk1 +disk2 +disk3 +disk4 +disk5 +disk6 +disk7 + + + + 90 + 2 + + + + + + 0 + 0 + True + Show output as MIX words + True + Word + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 89 + 34 + + + + + + 0 + 0 + True + Show output as decimal numbers + True + Decimal + True + GTK_RELIEF_NORMAL + True + False + False + True + wordradio + + + + 154 + 34 + + + + + 0 + True + False + GTK_PACK_END + + + + + + + + External programs + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + True + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + + + + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + True + True + 0 + + + + True + + + + 0 + 0 + True + True + True + True + 0 + xterm -e vi %s + True + * + False + + + 256 + 12 + + + + + + 0 + 0 + True + Editor command (e.g xterm -e vi %s) + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 8 + 15 + + + + + 0 + True + True + + + + + + True + + + + 0 + 0 + True + True + True + True + 0 + mixasm %s + True + * + False + + + 255 + 4 + + + + + + 0 + 0 + True + MIX sssembler command (e.g. mixasm %s) + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 8 + 8 + + + + + 0 + True + True + + + + + 0 + True + True + + + + + + + + Symbol table + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + 245 + 265 + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + + + + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + GTK_RELIEF_NORMAL + True + 0 + + + + + True + 0.5 + 0.5 + 0 + 0 + 0 + 0 + 0 + 0 + + + + True + False + 2 + + + + True + gtk-close + 4 + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + _Close + True + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + + + + + + 0 + False + True + GTK_PACK_END + + + + + + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + False + True + True + True + + + + + 0 + True + True + + + + + + + + MIXAL source + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + 570 + 225 + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST + + + + True + False + 0 + + + + True + GTK_SHADOW_OUT + GTK_POS_LEFT + GTK_POS_TOP + + + + 2 + True + True + GTK_ORIENTATION_HORIZONTAL + GTK_TOOLBAR_ICONS + True + True + + + + True + Run + Run + True + gtk-go-forward + True + True + True + + + + False + True + + + + + + True + Next + Step + True + gtk-goto-last + True + True + True + + + + False + True + + + + + + True + Clear breakpoints + Clear + True + gtk-clear + True + True + True + + + + False + True + + + + + + True + Symbol table + Symbols + True + gtk-index + True + True + True + + + + False + True + + + + + + True + True + True + True + + + False + False + + + + + + True + Source code font + Font + True + gtk-select-font + True + True + True + + + + False + True + + + + + + True + True + True + True + + + False + False + + + + + + True + Attach window + + True + gtk-dnd + True + True + True + + + False + True + + + + + + + 0 + False + False + + + + + + True + False + 0 + + + + + + + 0 + True + True + + + + + + True + True + + + 0 + False + False + + + + + + + + Devices + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + 550 + 250 + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST + + + + + + + True + False + 0 + + + + True + GTK_SHADOW_OUT + GTK_POS_LEFT + GTK_POS_TOP + + + + 2 + True + True + GTK_ORIENTATION_HORIZONTAL + GTK_TOOLBAR_ICONS + True + True + + + + True + Device directory + Directory + True + gtk-home + True + True + True + + + + False + True + + + + + + True + Output format + Output + True + gtk-zoom-100 + True + True + True + + + + False + True + + + + + + True + True + True + True + + + False + False + + + + + + True + Output font + Font + True + gtk-select-font + True + True + True + + + + False + True + + + + + + True + True + True + True + + + False + False + + + + + + True + + True + gtk-dnd + True + True + True + + + False + True + + + + + + + 0 + False + False + + + + + + True + False + 0 + + + + + + + 0 + True + True + + + + + + + + Devices directory + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + + + + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -5 + + + + + + 0 + False + False + GTK_PACK_END + + + + + + 25 + True + False + 11 + + + + True + Directory + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + True + False + True + 0 + + True + * + False + + + 0 + True + True + + + + + + True + True + gtk-open + True + GTK_RELIEF_NORMAL + True + + + + 0 + False + False + + + + + 0 + False + True + + + + + + + + Virtual machine + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + 640 + 268 + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST + + + + True + False + 0 + + + + True + GTK_SHADOW_OUT + GTK_POS_LEFT + GTK_POS_TOP + + + + True + True + GTK_ORIENTATION_HORIZONTAL + GTK_TOOLBAR_ICONS + True + True + + + + True + Font + True + gtk-select-font + True + True + True + + + + False + True + + + + + + True + True + True + True + + + False + False + + + + + + True + + True + gtk-dnd + True + True + True + + + False + True + + + + + + + 0 + False + False + + + + + + 5 + True + 0 + 0.5 + GTK_SHADOW_ETCHED_IN + + + + True + False + 0 + + + + 1 + True + False + 1 + + + + 2 + True + 0 + 0.5 + GTK_SHADOW_ETCHED_IN + + + + 8 + True + 3 + 6 + False + 6 + 11 + + + + 0 + 0 + True + A + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + + 0 + 0 + True + I1 + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 0 + + + 2 + 3 + 0 + 1 + fill + + + + + + + 0 + 0 + True + I2 + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 0 + + + 2 + 3 + 1 + 2 + fill + + + + + + + 0 + 0 + True + True + True + False + True + 0 + + True + * + False + 19 + + + + 1 + 2 + 0 + 1 + + + + + + + + 0 + 0 + True + True + False + True + 0 + + True + * + False + 9 + + + + 3 + 4 + 1 + 2 + + + + + + + + 0 + 0 + True + True + False + True + 0 + + True + * + False + 9 + + + + 3 + 4 + 0 + 1 + + + + + + + + 0 + 0 + True + X + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + 1 + 1 + 2 + fill + + + + + + + 16 + 16 + True + I3 + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 0 + + + 2 + 3 + 2 + 3 + fill + + + + + + + 0 + 0 + True + I4 + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 0 + + + 4 + 5 + 0 + 1 + fill + + + + + + + 16 + 16 + True + I5 + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 0 + + + 4 + 5 + 1 + 2 + fill + + + + + + + 16 + 16 + True + I6 + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 0 + + + 4 + 5 + 2 + 3 + fill + + + + + + + 0 + 0 + True + J + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + 1 + 2 + 3 + fill + + + + + + + 0 + 0 + True + True + False + True + 0 + + True + * + False + 19 + + + + 1 + 2 + 1 + 2 + + + + + + + + 0 + 0 + True + True + False + True + 0 + + True + * + False + 9 + + + + 5 + 6 + 0 + 1 + + + + + + + + 0 + 0 + True + True + False + True + 0 + + True + * + False + 9 + + + + 5 + 6 + 1 + 2 + + + + + + + + 0 + 0 + True + True + False + True + 0 + + True + * + False + 9 + + + + 5 + 6 + 2 + 3 + + + + + + + + 0 + 0 + True + True + False + True + 0 + + True + * + False + 9 + + + + 3 + 4 + 2 + 3 + + + + + + + + True + False + 0 + + + + 0 + 0 + True + True + False + True + 0 + + True + * + False + 9 + + + + 0 + False + False + + + + + + + + + 1 + 2 + 2 + 3 + fill + fill + + + + + + + + True + Registers + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 2 + 0 + + + label_item + + + + + 5 + False + True + + + + + + True + False + 0 + + + + 2 + True + 0 + 0.5 + GTK_SHADOW_ETCHED_IN + + + + 1 + True + False + 5 + + + + 2 + 0 + 0 + True + Greater + True + G + True + GTK_RELIEF_NORMAL + True + False + False + True + + + + 0 + False + False + + + + + + 2 + 0 + 0 + True + Equal + True + E + True + GTK_RELIEF_NORMAL + True + False + False + True + greater_radio + + + + 0 + False + False + + + + + + 2 + 0 + 0 + True + Lesser + True + L + True + GTK_RELIEF_NORMAL + True + False + False + True + greater_radio + + + + 0 + False + False + + + + + + 7 + True + + + 0 + False + False + + + + + + True + True + Overflow + True + GTK_RELIEF_NORMAL + True + False + False + True + + + + 0 + False + False + + + + + + + + True + Flags + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 2 + 0 + + + label_item + + + + + 0 + False + False + + + + + + + + + + 2 + True + 0 + 0.5 + GTK_SHADOW_ETCHED_IN + + + + 4 + True + False + 1 + + + + 0 + 0 + True + True + False + True + 4 + 0 + True + * + False + 6 + + + 5 + False + False + + + + + + True + View loc address + True + GTK_RELIEF_NORMAL + True + + + + + True + gtk-jump-to + 4 + 0.5 + 0.5 + 0 + 0 + + + + + 1 + False + False + + + + + + + + True + Location + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 2 + 0 + + + label_item + + + + + 0 + False + False + GTK_PACK_END + + + + + 5 + False + True + + + + + + 2 + True + 0 + 0.5 + GTK_SHADOW_ETCHED_IN + + + + 5 + True + True + 5 + + + + 0 + 0 + True + Uptime: + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + 0 + 0 + True + 00000000 + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 5 + 0 + + + 0 + False + False + + + + + + 0 + 0 + True + Elapsed: + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 3 + False + False + + + + + + 0 + 0 + True + 000000 + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 5 + 0 + + + 0 + False + False + + + + + + 0 + 0 + True + Program: + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 2 + False + False + + + + + + 0 + 0 + True + 000000 + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 5 + 0 + + + 0 + False + False + + + + + + + + True + Times + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 2 + 0 + + + label_item + + + + + 5 + False + True + + + + + 2 + False + False + + + + + + 7 + True + 0 + 0.5 + GTK_SHADOW_ETCHED_IN + + + + 5 + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + GDK_BUTTON_PRESS_MASK + True + True + False + True + + + + + + + + True + Memory + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 2 + 0 + + + label_item + + + + + 3 + True + True + GTK_PACK_END + + + + + + + + True + MIX Virtual Machine + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 2 + 0 + + + label_item + + + + + 0 + True + True + + + + + + + + True + MIX Console input + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + True + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + + + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + 3 + True + True + 0 + + + + True + Enter up to 70 characters + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + True + True + True + 70 + + True + * + True + 70 + + + 0 + False + False + + + + + 0 + False + False + + + + + + + diff --git a/mixgtk/mixgtk.gladep b/mixgtk/mixgtk.gladep new file mode 100644 index 0000000..40a311a --- /dev/null +++ b/mixgtk/mixgtk.gladep @@ -0,0 +1,9 @@ + + + + + Mixgtk + mixgtk + . + FALSE + diff --git a/mixgtk/mixgtk.h b/mixgtk/mixgtk.h new file mode 100644 index 0000000..913c245 --- /dev/null +++ b/mixgtk/mixgtk.h @@ -0,0 +1,49 @@ +/* -*-c-*- ---------------- mixgtk.h : + * Gmixvm initialisation and cleanup functions + * ------------------------------------------------------------------ + * Last change: Time-stamp: <2001-04-29 12:06:48 jao> + * ------------------------------------------------------------------ + * Copyright (C) 2001, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + + +#ifndef MIXGTK_H +#define MIXGTK_H + +#include +#include + +/* the app files directory */ +#define MIXGTK_FILES_DIR ".mdk" + +/* initialise the app */ +extern gboolean +mixgtk_init (int argc, char *argv[]); + +/* enter the main mixgtk loop */ +extern void +mixgtk_main (void); + +/* clean up */ +extern void +mixgtk_release (void); + + + +#endif /* MIXGTK_H */ + diff --git a/mixgtk/mixgtk_cmd_dispatcher.c b/mixgtk/mixgtk_cmd_dispatcher.c new file mode 100644 index 0000000..dbb2909 --- /dev/null +++ b/mixgtk/mixgtk_cmd_dispatcher.c @@ -0,0 +1,547 @@ +/* -*-c-*- -------------- mixgtk_cmd_dispatcher.c : + * Implementation of the functions declared in mixgtk_cmd_dispatcher.h + * ------------------------------------------------------------------ + * $Id: mixgtk_cmd_dispatcher.c,v 1.24 2005/09/20 19:43:14 jao Exp $ + * ------------------------------------------------------------------ + * Copyright (C) 2001, 2002, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#ifdef HAVE_LIBHISTORY +# include +#endif + +#ifdef MAKE_GUILE +# include +#endif + +#include +#include +#include "mixgtk_mixvm.h" +#include "mixgtk_mixal.h" +#include "mixgtk_fontsel.h" +#include "mixgtk_config.h" +#include "mixgtk_cmd_dispatcher.h" + + +/* a mix vm command dispatcher */ +typedef struct mixgtk_dispatch_ +{ + mix_vm_cmd_dispatcher_t *dispatcher; /* the underlying cmd dispatcher */ + FILE *out; /* the dispatcher's output file */ + int fildes[2]; /* pipe for communication with the dispatcher */ + GtkWidget *prompt; /* the command prompt widget */ + GtkWidget *log; /* the dispatcher's messages echo area */ + GtkWidget *status; /* the status bar widget */ + guint context; /* context of the status bar messages */ + gchar *last_file; +} mixgtk_dispatch_data_t; + +static struct mixgtk_dispatch_ dis_data_ = {NULL}; + +static GtkWidget *ext_dlg_ = NULL; +static GtkWidget *ed_entry_ = NULL; +static GtkWidget *asm_entry_ = NULL; + +static const gchar *ED_NAME_ = "editor_entry"; +static const gchar *ASM_NAME_ = "mixasm_entry"; + +static const gchar *TITLE_FORMAT_ = "gmixvm - %s"; + +static void +log_command_ (mixgtk_dispatch_data_t *dis, const gchar *cmd) +{ + GtkTextBuffer *buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (dis->log)); + GtkTextIter end; + + gtk_text_buffer_get_end_iter (buf, &end); + gtk_text_buffer_place_cursor (buf, &end); + gtk_text_buffer_insert_at_cursor (buf, "MIX> ", -1); + gtk_text_buffer_insert_at_cursor (buf, cmd, -1); + gtk_text_buffer_insert_at_cursor (buf, "\n", -1); + +#ifdef HAVE_LIBHISTORY + add_history ((char *)cmd); +/* history_search ((char *)cmd, 0); */ + history_set_pos (history_base + history_length - 1); +#endif +} + +static void +flush_log_ (mixgtk_dispatch_data_t *dis) +{ + enum {BLKSIZE = 100}; + static gchar BUFFER[BLKSIZE]; + + GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (dis->log)); + GtkTextMark *mark; + GtkTextIter end; + ssize_t k; + + gtk_text_buffer_get_end_iter (buffer, &end); + gtk_text_buffer_place_cursor (buffer, &end); + + fflush (dis->out); + while ((k = read (dis->fildes[0], BUFFER, BLKSIZE)) != 0) + { + if (k == -1 && errno != EINTR) break; + if (k != -1) + gtk_text_buffer_insert_at_cursor (buffer, BUFFER, k); + } + + mark = gtk_text_buffer_get_insert (buffer); + gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (dis->log), mark, 0, + TRUE, 0, 0); +} + +/* hooks */ +static void +global_post_hook_ (mix_vm_cmd_dispatcher_t *dis, + mix_vm_command_t cmd, const gchar *arg, gpointer data) +{ + flush_log_ ((mixgtk_dispatch_data_t *)data); + mixgtk_mixvm_update_vm_widgets (); +} + +static void +load_post_hook_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg, + gpointer data) +{ + static glong id = -1; + + if (mix_vm_cmd_dispatcher_get_last_result (dis)) + { + GtkWindow *mainw = + GTK_WINDOW (mixgtk_widget_factory_get_dialog (MIXGTK_MAIN)); + + if (dis_data_.last_file) g_free (dis_data_.last_file); + dis_data_.last_file = g_strdup_printf (TITLE_FORMAT_, arg); + gtk_window_set_title (mainw, dis_data_.last_file); + + mixgtk_mixal_load_file (); + mixgtk_mixal_update (); + mixgtk_mixal_update_bp_all (); + + if (id != -1) + gtk_statusbar_remove (GTK_STATUSBAR (dis_data_.status), + dis_data_.context, (guint)id); + id = + gtk_statusbar_push (GTK_STATUSBAR (dis_data_.status), dis_data_.context, + dis_data_.last_file); + } +} + +static void +run_post_hook_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg, + gpointer data) +{ + mixgtk_mixal_update (); +} + +static void +next_post_hook_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg, + gpointer data) +{ + mixgtk_mixal_update (); +} + +static void +linebp_post_hook_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg, + gpointer data) +{ + if (arg && strlen (arg)) mixgtk_mixal_update_bp_at_line (atoi (arg)); +} + +static void +addrbp_post_hook_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg, + gpointer data) +{ + if (arg && strlen (arg)) mixgtk_mixal_update_bp_at_address (atoi (arg)); +} + +static void +allbp_post_hook_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg, + gpointer data) +{ + mixgtk_mixal_update_bp_all (); +} + + +static void +install_hooks_ (void) +{ + mix_vm_cmd_dispatcher_global_post_hook (dis_data_.dispatcher, + global_post_hook_, + (gpointer)(&dis_data_)); + mix_vm_cmd_dispatcher_post_hook (dis_data_.dispatcher, + MIX_CMD_LOAD, load_post_hook_, + NULL); + mix_vm_cmd_dispatcher_post_hook (dis_data_.dispatcher, + MIX_CMD_RUN, run_post_hook_, + NULL); + mix_vm_cmd_dispatcher_post_hook (dis_data_.dispatcher, + MIX_CMD_NEXT, next_post_hook_, + NULL); + mix_vm_cmd_dispatcher_post_hook (dis_data_.dispatcher, + MIX_CMD_SBP, linebp_post_hook_, + NULL); + mix_vm_cmd_dispatcher_post_hook (dis_data_.dispatcher, + MIX_CMD_CBP, linebp_post_hook_, + NULL); + mix_vm_cmd_dispatcher_post_hook (dis_data_.dispatcher, + MIX_CMD_SBPA, addrbp_post_hook_, + NULL); + mix_vm_cmd_dispatcher_post_hook (dis_data_.dispatcher, + MIX_CMD_CBPA, addrbp_post_hook_, + NULL); + mix_vm_cmd_dispatcher_post_hook (dis_data_.dispatcher, + MIX_CMD_CABP, allbp_post_hook_, + NULL); +} + +/* configuration stuff */ +static const gchar *EDITOR_KEY_ = "Editor"; +static const gchar *MIXASM_KEY_ = "Mixasm"; + +static void +read_config_ (void) +{ + const gchar *editor = mixgtk_config_get (EDITOR_KEY_); + const gchar *assem = mixgtk_config_get (MIXASM_KEY_); + + if (!editor) + { + static const gchar *ENV[] = {"MDK_EDITOR", "X_EDITOR", NULL}; + gchar *edit = NULL; + int k = 0; + while (!edit && ENV[k]) edit = getenv (ENV[k++]); + if (edit) edit = g_strconcat (edit, " %s", NULL); + else edit = g_strdup ("xterm -e vi %s"); + mix_vm_cmd_dispatcher_set_editor (dis_data_.dispatcher, edit); + g_free (edit); + } + else + { + mix_vm_cmd_dispatcher_set_editor (dis_data_.dispatcher, editor); + } + if (!assem) assem = "mixasm %s"; + mix_vm_cmd_dispatcher_set_assembler (dis_data_.dispatcher, assem); + +} + +void +on_external_programs_activate () +{ + if (!ext_dlg_) + { + ext_dlg_ = mixgtk_widget_factory_get_dialog (MIXGTK_EXTERNPROG_DIALOG); + g_return_if_fail (ext_dlg_ != NULL); + ed_entry_ = mixgtk_widget_factory_get_child_by_name + (MIXGTK_EXTERNPROG_DIALOG, ED_NAME_); + g_assert (ed_entry_); + asm_entry_ = mixgtk_widget_factory_get_child_by_name + (MIXGTK_EXTERNPROG_DIALOG, ASM_NAME_); + g_assert (asm_entry_); + } + gtk_entry_set_text (GTK_ENTRY (ed_entry_), + mix_vm_cmd_dispatcher_get_editor (dis_data_.dispatcher)); + gtk_entry_set_text (GTK_ENTRY (asm_entry_), + mix_vm_cmd_dispatcher_get_assembler + (dis_data_.dispatcher)); + gtk_widget_show (ext_dlg_); + if (gtk_dialog_run (GTK_DIALOG (ext_dlg_)) == GTK_RESPONSE_OK) + { + const gchar *value = gtk_entry_get_text (GTK_ENTRY (ed_entry_)); + mix_vm_cmd_dispatcher_set_editor (dis_data_.dispatcher, value); + mixgtk_config_update (EDITOR_KEY_, value); + value = gtk_entry_get_text (GTK_ENTRY (asm_entry_)); + mix_vm_cmd_dispatcher_set_assembler (dis_data_.dispatcher, value); + mixgtk_config_update (MIXASM_KEY_, value); + } + + gtk_widget_hide (ext_dlg_); +} + +/* initialise the command dispatcher */ +gboolean +mixgtk_cmd_dispatcher_init (mixgtk_dialog_id_t top) +{ + static gboolean restart = FALSE; + gchar *text = NULL; + + ext_dlg_ = NULL; + ed_entry_ = NULL; + asm_entry_ = NULL; + + dis_data_.prompt = + mixgtk_widget_factory_get (top, MIXGTK_WIDGET_PROMPT); + g_return_val_if_fail (dis_data_.prompt != NULL, FALSE); + + if (dis_data_.log) + text = gtk_editable_get_chars (GTK_EDITABLE (dis_data_.log), 0, -1); + + dis_data_.log = + mixgtk_widget_factory_get (top, MIXGTK_WIDGET_LOG); + + g_return_val_if_fail (dis_data_.log != NULL, FALSE); + + if (text) + { + gtk_text_buffer_insert_at_cursor + (gtk_text_view_get_buffer (GTK_TEXT_VIEW (dis_data_.log)), text, -1); + g_free (text); + } + + if (!dis_data_.dispatcher) + { + static const gchar *HISTORY_FILE = "gmixvm.history"; + static gint HISTORY_SIZE = 100; + mix_config_t *config = mixgtk_config_get_mix_config (); + + int r = pipe (dis_data_.fildes); + g_return_val_if_fail (r == 0, FALSE); + /* connect stdout/stderr to the pipe's write end */ + if (dup2 (dis_data_.fildes[1], STDOUT_FILENO) == -1 + || dup2 (dis_data_.fildes[1], STDOUT_FILENO) == -1) + return FALSE; + dis_data_.out = fdopen (dis_data_.fildes[1], "w"); + g_return_val_if_fail (dis_data_.out != NULL, FALSE); + r = fcntl (dis_data_.fildes[0], F_GETFL, 0); + g_return_val_if_fail (r != -1, FALSE); + r |= O_NONBLOCK; + r = fcntl(dis_data_.fildes[0], F_SETFL, r); + g_return_val_if_fail (r != -1, FALSE); + + if (!mix_config_get_history_file (config)) + mix_config_set_history_file (config, HISTORY_FILE); + if (mix_config_get_history_size (config) == 0) + mix_config_set_history_size (config, HISTORY_SIZE); + + dis_data_.dispatcher = + mix_vm_cmd_dispatcher_new_with_config (dis_data_.out, + dis_data_.out, + config); + mix_vm_cmd_dispatcher_print_time (dis_data_.dispatcher, FALSE); + + install_hooks_ (); + } + + dis_data_.status = + mixgtk_widget_factory_get (MIXGTK_MAIN, MIXGTK_WIDGET_STATUSBAR); + g_return_val_if_fail (dis_data_.status != NULL, FALSE); + dis_data_.context = gtk_statusbar_get_context_id (GTK_STATUSBAR + (dis_data_.status), + "cmd_dis_context"); + if (!restart) read_config_ (); + if (dis_data_.last_file) + gtk_window_set_title + (GTK_WINDOW (mixgtk_widget_factory_get_dialog (MIXGTK_MAIN)), + dis_data_.last_file); + + mixgtk_fontsel_set_font (MIX_FONT_LOG, dis_data_.log); + mixgtk_fontsel_set_font (MIX_FONT_PROMPT, dis_data_.prompt); + + restart = TRUE; + return TRUE; +} + +/* dispatch an externally provided command */ +#ifdef MAKE_GUILE +static gboolean +try_guile_ (const gchar *command) +{ + if (command && command[0] == '(' && command[strlen (command) - 1] == ')') + { + mixguile_interpret_command (command); + return TRUE; + } + return FALSE; +} +#else +# define try_guile_(ignored) FALSE +#endif + +void +mixgtk_cmd_dispatcher_dispatch (const gchar *command) +{ + GtkWidget *entry = dis_data_.prompt; + g_return_if_fail (command != NULL); + g_assert (entry != NULL); + gtk_entry_set_text (GTK_ENTRY (entry), command); + log_command_ (&dis_data_, command); + if (!try_guile_ (command)) + mix_vm_cmd_dispatcher_dispatch_text (dis_data_.dispatcher, command); + gtk_entry_set_text (GTK_ENTRY (entry), ""); +} + +/* get times */ +void +mixgtk_cmd_dispatcher_get_times (gint *uptime, gint *progtime, gint *laptime) +{ + if (uptime != NULL) + *uptime = mix_vm_cmd_dispatcher_get_uptime (dis_data_.dispatcher); + if (progtime != NULL) + *progtime = mix_vm_cmd_dispatcher_get_progtime (dis_data_.dispatcher); + if (laptime != NULL) + *laptime = mix_vm_cmd_dispatcher_get_laptime (dis_data_.dispatcher); +} + +/* get the underlying vm */ +mix_vm_t * +mixgtk_cmd_dispatcher_get_vm (void) +{ + return (mix_vm_t *) mix_vm_cmd_dispatcher_get_vm (dis_data_.dispatcher); +} + +/* get the current source file */ +const gchar * +mixgtk_cmd_dispatcher_get_src_path (void) +{ + return mix_vm_cmd_dispatcher_get_src_file_path (dis_data_.dispatcher); +} + +/* get the mix cmd dispatcher */ +mix_vm_cmd_dispatcher_t * +mixgtk_cmd_dispatcher_get_mix_dispatcher (void) +{ + return dis_data_.dispatcher; +} + +/* process commands */ +void +complete_command_ (void) +{ + GtkEntry *entry = GTK_ENTRY (dis_data_.prompt); + gchar *prefix = NULL; + const gchar *text = gtk_entry_get_text (entry); + const GList *cmds = + mix_vm_cmd_dispatcher_complete (dis_data_.dispatcher, text, &prefix); + + if (prefix != NULL) + { + GtkTextBuffer *buf = + gtk_text_view_get_buffer (GTK_TEXT_VIEW (dis_data_.log)); + + gtk_entry_set_text (entry, prefix); + if (g_list_length ((GList *)cmds) > 1) + { + static gchar BUFFER[25]; + gint k = 0; + gtk_text_buffer_insert_at_cursor (buf, "Completions:\n", -1); + while (cmds) + { + g_snprintf (BUFFER, 25, "%-12s", (const char*)cmds->data); + ++k; + gtk_text_buffer_insert_at_cursor (buf, BUFFER, -1); + if (k%5 == 0) + gtk_text_buffer_insert_at_cursor (buf, "\n", -1); + + cmds = cmds->next; + } + if (k%5 != 0) + gtk_text_buffer_insert_at_cursor (buf, "\n", -1); + } + else + { + gint pos = strlen (prefix); + gtk_editable_insert_text (GTK_EDITABLE (entry), " ", 1, &pos); + } + flush_log_ (&dis_data_); + g_free (prefix); + } +} + +int +on_command_prompt_key_press_event (GtkEntry *w, GdkEventKey *e, gpointer d) +{ + guint key = e->keyval; + gboolean result = FALSE; + +#ifdef HAVE_LIBHISTORY + HIST_ENTRY *entry = NULL; + if (key == GDK_Up) + { + entry = previous_history (); + if (entry && entry->line) + gtk_entry_set_text (w, entry->line); + result = TRUE; + } + if (key == GDK_Down) + { + entry = next_history (); + if (entry && entry->line) + gtk_entry_set_text (w, entry->line); + result = TRUE; + } +#endif + + if (key == GDK_Tab) + { + complete_command_ (); + result = TRUE; + } + + if (result) gtk_editable_set_position (GTK_EDITABLE (w), -1); + + return result; +} + +void +on_command_prompt_activate (GtkEntry *prompt, gpointer data) +{ + gchar *text = + g_strstrip (gtk_editable_get_chars (GTK_EDITABLE (prompt), 0, -1)); + if (text && *text) + { + log_command_ (&dis_data_, text); + if (!try_guile_ (text)) + mix_vm_cmd_dispatcher_dispatch_text (dis_data_.dispatcher, text); + gtk_entry_set_text (prompt, ""); + } + g_free (text); +} + +void +on_log_font_activate () +{ + GtkWidget *w[] = { dis_data_.log }; + mixgtk_fontsel_query_font (MIX_FONT_LOG, w, 1); +} + +void +on_prompt_font_activate () +{ + GtkWidget *w[] = { dis_data_.prompt }; + mixgtk_fontsel_query_font (MIX_FONT_PROMPT, w, 1); +} + +void +mixgtk_cmd_dispatcher_update_fonts (void) +{ + mixgtk_fontsel_set_font (MIX_FONT_LOG, dis_data_.log); + mixgtk_fontsel_set_font (MIX_FONT_PROMPT, dis_data_.prompt); +} diff --git a/mixgtk/mixgtk_cmd_dispatcher.h b/mixgtk/mixgtk_cmd_dispatcher.h new file mode 100644 index 0000000..25ca240 --- /dev/null +++ b/mixgtk/mixgtk_cmd_dispatcher.h @@ -0,0 +1,61 @@ +/* -*-c-*- ---------------- mixgtk_cmd_dispatcher.h : + * functions to access the command dispatcher + * ------------------------------------------------------------------ + * $Id: mixgtk_cmd_dispatcher.h,v 1.6 2005/09/20 19:43:14 jao Exp $ + * ------------------------------------------------------------------ + * Copyright (C) 2001, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + + +#ifndef MIXGTK_CMD_DISPATCHER_H +#define MIXGTK_CMD_DISPATCHER_H + +#include +#include +#include "mixgtk_widgets.h" + +/* initialise the command dispatcher */ +extern gboolean +mixgtk_cmd_dispatcher_init (mixgtk_dialog_id_t top); + +extern void +mixgtk_cmd_dispatcher_update_fonts (void); + +/* dispatch an externally provided command */ +extern void +mixgtk_cmd_dispatcher_dispatch (const gchar *command); + +/* get times */ +extern void +mixgtk_cmd_dispatcher_get_times (gint *uptime, gint *progtime, gint *laptime); + +/* get the underlying vm */ +extern mix_vm_t * +mixgtk_cmd_dispatcher_get_vm (void); + +/* get the current source file */ +extern const gchar * +mixgtk_cmd_dispatcher_get_src_path (void); + +/* get the mix cmd dispatcher */ +extern mix_vm_cmd_dispatcher_t * +mixgtk_cmd_dispatcher_get_mix_dispatcher (void); + + +#endif /* MIXGTK_CMD_DISPATCHER_H */ + diff --git a/mixgtk/mixgtk_config.c b/mixgtk/mixgtk_config.c new file mode 100644 index 0000000..275d182 --- /dev/null +++ b/mixgtk/mixgtk_config.c @@ -0,0 +1,113 @@ +/* -*-c-*- -------------- mixgtk_config.c : + * Implementation of the functions declared in mixgtk_config.h + * ------------------------------------------------------------------ + * $Id: mixgtk_config.c,v 1.10 2005/09/20 19:43:14 jao Exp $ + * ------------------------------------------------------------------ + * Copyright (C) 2001, 2002, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include +#include +#include + +#include +#include +#include +#include "mixgtk.h" +#include "mixgtk_config.h" + +static const gchar *MIXGTK_CONFIG_FILE_ = "gmixvm.config"; +static const gchar *SHOW_TB_KEY = "Toolbars"; +static const gchar *TB_YES = "Yes"; +static const gchar *TB_NO = "No"; + +static mix_config_t *config_ = NULL; + +/* load configuration */ +gboolean +mixgtk_config_load (void) +{ + if (config_ == NULL) + { + gchar *cdir = g_strconcat (g_get_home_dir (), G_DIR_SEPARATOR_S, + MIXGTK_FILES_DIR, NULL); + config_ = mix_config_new (cdir, MIXGTK_CONFIG_FILE_); + g_free (cdir); + } + return (config_ != NULL); +} + +/* get mixlib config */ +mix_config_t * +mixgtk_config_get_mix_config (void) +{ + return config_; +} + +/* autosave state */ +gboolean +mixgtk_config_is_autosave (void) +{ + return mix_config_is_autosave (config_); +} + +void +mixgtk_config_set_autosave (gboolean autosave) +{ + mix_config_set_autosave (config_, autosave); +} + +/* update config item */ +void +mixgtk_config_update (const gchar *key, const gchar *value) +{ + mix_config_update (config_, key, value); +} + +/* get config item */ +const gchar * +mixgtk_config_get (const gchar *key) +{ + return mix_config_get (config_, key); +} + +void +mixgtk_config_remove (const char *key) +{ + mix_config_remove (config_, key); +} + +/* save configuration */ +void +mixgtk_config_save (void) +{ + mix_config_save (config_); +} + +gboolean +mixgtk_config_show_toolbars (void) +{ + const gchar *show = mixgtk_config_get (SHOW_TB_KEY); + return (!show || !strcmp (show, TB_YES)); +} + +void +mixgtk_config_set_show_toolbars (gboolean show) +{ + mixgtk_config_update (SHOW_TB_KEY, show? TB_YES : TB_NO); +} diff --git a/mixgtk/mixgtk_config.h b/mixgtk/mixgtk_config.h new file mode 100644 index 0000000..7c3f548 --- /dev/null +++ b/mixgtk/mixgtk_config.h @@ -0,0 +1,70 @@ +/* -*-c-*- ---------------- mixgtk_config.h : + * Configuration functions declarations. + * ------------------------------------------------------------------ + * $Id: mixgtk_config.h,v 1.7 2005/09/20 19:43:14 jao Exp $ + * ------------------------------------------------------------------ + * Copyright (C) 2001, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + + +#ifndef MIXGTK_CONFIG_H +#define MIXGTK_CONFIG_H + +#include +#include + +/* load configuration */ +extern gboolean +mixgtk_config_load (void); + +/* get mix config */ +extern mix_config_t * +mixgtk_config_get_mix_config (void); + +/* autosave state */ +extern gboolean +mixgtk_config_is_autosave (void); + +extern void +mixgtk_config_set_autosave (gboolean autosave); + +/* update config item */ +extern void +mixgtk_config_update (const gchar *key, const gchar *value); + +/* get config item */ +extern const gchar * +mixgtk_config_get (const gchar *key); + +/* remove config item */ +extern void +mixgtk_config_remove (const gchar *key); + +/* save configuration */ +extern void +mixgtk_config_save (void); + +/* shared config params */ +extern gboolean +mixgtk_config_show_toolbars (void); + +extern void +mixgtk_config_set_show_toolbars (gboolean show); + +#endif /* MIXGTK_CONFIG_H */ + diff --git a/mixgtk/mixgtk_device.c b/mixgtk/mixgtk_device.c new file mode 100644 index 0000000..203933c --- /dev/null +++ b/mixgtk/mixgtk_device.c @@ -0,0 +1,625 @@ +/* -*-c-*- ---------------- mixgtk_device.c : + * actual types for mixgtk devices + * ------------------------------------------------------------------ + * $Id: mixgtk_device.c,v 1.26 2005/09/20 19:43:14 jao Exp $ + * ------------------------------------------------------------------ + * Copyright (C) 2001, 2002, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + + +#include +#include +#include + +#include +#include + +#include "mixgtk.h" +#include "mixgtk_gen_handlers.h" +#include "mixgtk_widgets.h" +#include "mixgtk_fontsel.h" +#include "mixgtk_config.h" +#include "mixgtk_cmd_dispatcher.h" +#include "mixgtk_device.h" + +#define BIN_DEV_COL_ 5 + +static const gchar *DEV_FORMAT_KEY_ = "Device.format"; + +/* device container */ +static GtkNotebook *dev_nb_ = NULL; +/* devdir dialog */ +static GtkWidget *devdir_dlg_ = NULL; +static GtkEntry *devdir_entry_ = NULL; +/* terminal input dialog */ +static GtkWidget *input_dlg_ = NULL; +static GtkEntry *input_dlg_entry_ = NULL; + +/** configuration stuff */ +#define LAST_BIN_DEV_ mix_dev_DISK_7 +static GtkWidget *devdlg_ = NULL; +static GtkWidget *dtoggle_ = NULL; +static GtkWidget *wtoggle_ = NULL; +static GtkWidget *combo_ = NULL; + +/* virtual machine */ +static mix_vm_t *vm_ = NULL; +/* dec settings */ +static gint32 decs_ = 0; +static gint32 new_decs_ = 0; + +/* macros manipulating dec settings */ +#define IS_DEC(flags,type) (((flags) >> (type)) & 1) +#define SET_DEC(flags,type) ((flags) |= (1<<(type))) +#define CLEAR_DEC(flags,type) ((flags) &= ~(1<<(type))) + +/* a mixgtk device */ +struct mixgtk_device_t +{ + mix_device_t device; + GtkWidget *widget; + GtkWidget *scroll; +}; + +struct mixgtk_bin_device_t +{ + struct mixgtk_device_t gtk_device; + guint last_insert; + GtkListStore *store; + gboolean dec; +}; + +/* callbacks for output devices */ +static void +write_char_ (struct mixgtk_device_t *dev, const mix_word_t *block) +{ + enum {MAX_BLOCK = 16, BUFF_SIZE = MAX_BLOCK * 5 + 2}; + static gchar BUFFER[BUFF_SIZE]; + + guint k, j; + GtkTextIter end; + GtkTextBuffer *buffer; + GtkTextMark *mark; + + for (k = 0; k < SIZES_[dev->device.type]; k++) + for (j = 1; j < 6; j++) + { + mix_char_t ch = mix_word_get_byte (block[k], j); + BUFFER[5 * k + j - 1] = mix_char_to_ascii (ch); + } + + BUFFER[5 * k] = '\n'; + BUFFER[5 * k + 1] = '\0'; + + buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (dev->widget)); + gtk_text_buffer_get_end_iter (buffer, &end); + gtk_text_buffer_place_cursor (buffer, &end); + gtk_text_buffer_insert_at_cursor (buffer, BUFFER, -1); + mark = gtk_text_buffer_get_insert (buffer); + gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (dev->widget), mark, 0, + TRUE, 0, 0); +} + +static const gchar * +get_word_string_ (mix_word_t w, gboolean dec) +{ + enum {BUFF_SIZE = 17}; + static gchar BUFFER[BUFF_SIZE] = { 0 }; + if (dec) + g_snprintf (BUFFER, BUFF_SIZE, "%s%011ld", + mix_word_is_negative (w)? "-" : "+", + mix_word_magnitude (w)); + else + mix_word_print_to_buffer (w, BUFFER); + return BUFFER; +} + +static void +write_bin_ (struct mixgtk_bin_device_t *dev, const mix_word_t *block) +{ + guint k, col; + gboolean dec = FALSE; + size_t len; + + GtkTreeView *view = GTK_TREE_VIEW (dev->gtk_device.widget); + GtkListStore *store = dev->store; + GtkTreeIter iter; + + g_assert (view); + g_assert (store); + + dec = IS_DEC(decs_, dev->gtk_device.device.type); + + for (k = 0, len = SIZES_[dev->gtk_device.device.type]; + k < len; k += BIN_DEV_COL_) + { + gtk_list_store_append (store, &iter); + for (col = 0; col < BIN_DEV_COL_; ++col) + gtk_list_store_set (store, &iter, + col, get_word_string_ (block[k + col], dec), + col + BIN_DEV_COL_, (guint)block[k + col], + -1); + dev->last_insert++; + } +} + +static gboolean +write_ (mix_device_t *dev, const mix_word_t *block) +{ + struct mixgtk_device_t *gtkdev = (struct mixgtk_device_t *) dev; + + if (dev->type != mix_dev_CONSOLE && !(DEF_DEV_VTABLE_->write)(dev, block)) + return FALSE; + + if (MODES_[dev->type] == mix_dev_CHAR) write_char_ (gtkdev, block); + else write_bin_ ((struct mixgtk_bin_device_t *)gtkdev, block); + + gtk_notebook_set_current_page (dev_nb_, + gtk_notebook_page_num (dev_nb_, + gtkdev->scroll)); + + return TRUE; +} + +static gboolean +read_cons_ (mix_word_t *block) +{ + gchar *text; + size_t i, j; + + if (input_dlg_ == NULL) + { + input_dlg_ = mixgtk_widget_factory_get_dialog (MIXGTK_INPUT_DIALOG); + g_assert (input_dlg_); + input_dlg_entry_ = GTK_ENTRY (mixgtk_widget_factory_get_child_by_name + (MIXGTK_INPUT_DIALOG, "input_entry")); + g_assert (input_dlg_entry_); + } + + gtk_entry_set_text (input_dlg_entry_, ""); + gtk_dialog_run (GTK_DIALOG (input_dlg_)); + gtk_widget_hide (input_dlg_); + text = g_strdup_printf ("%-70s", gtk_entry_get_text (input_dlg_entry_)); + for (i = 0; i < 70; ++i) + for (j = 0; j < 5; ++j) + mix_word_set_byte (block + i, j + 1, + mix_char_to_byte + (mix_ascii_to_char (text[5 * i + j]))); + g_free (text); + return TRUE; +} + +static gboolean +read_ (mix_device_t *dev, mix_word_t *block) +{ + struct mixgtk_device_t *gtkdev = (struct mixgtk_device_t *) dev; + + if (dev->type == mix_dev_CONSOLE && !read_cons_ (block)) return FALSE; + + if (dev->type != mix_dev_CONSOLE && !(DEF_DEV_VTABLE_->read)(dev, block)) + return FALSE; + + if (MODES_[dev->type] == mix_dev_CHAR) write_char_ (gtkdev, block); + else write_bin_ ((struct mixgtk_bin_device_t *)gtkdev, block); + + gtk_notebook_set_current_page (dev_nb_, + gtk_notebook_page_num (dev_nb_, + gtkdev->scroll)); + return TRUE; +} + +static gboolean +ioc_ (mix_device_t *dev, mix_short_t cmd) +{ + return (DEF_DEV_VTABLE_->ioc)(dev, cmd); +} + +static gboolean +busy_ (const mix_device_t *dev) +{ + return (DEF_DEV_VTABLE_->busy)(dev); +} + +static void +destroy_ (mix_device_t *dev) +{ + struct mixgtk_device_t *gtkdev = (struct mixgtk_device_t *)dev; + if (MODES_[dev->type] == mix_dev_BIN) { + struct mixgtk_bin_device_t * bdev = (struct mixgtk_bin_device_t *)dev; + gtk_list_store_clear (bdev->store); + g_object_unref ((gpointer)bdev->store); + } + (DEF_DEV_VTABLE_->destroy) (dev); + gtk_notebook_remove_page (dev_nb_, + gtk_notebook_page_num (dev_nb_, + gtkdev->scroll)); +} + +static mix_device_vtable_t MIXGTK_VTABLE_ = { + write_, read_, ioc_, busy_, destroy_ +}; + +/* create the gui part of the device */ +static void +mixgtk_device_construct_gui_ (struct mixgtk_device_t *dev) +{ + GtkWidget *label = gtk_label_new (DEF_NAMES_[dev->device.type]); + + g_assert (label); + + dev->scroll = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (dev->scroll), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + + if (MODES_[dev->device.type] == mix_dev_CHAR) + { + dev->widget = gtk_text_view_new (); + gtk_text_view_set_editable (GTK_TEXT_VIEW (dev->widget), FALSE); + } + else + { + gint k; + struct mixgtk_bin_device_t *bindev = (struct mixgtk_bin_device_t *)dev; + GtkCellRenderer *renderer = gtk_cell_renderer_text_new (); + GType *types = g_new (GType, BIN_DEV_COL_ * 2); + + for (k = 0; k < BIN_DEV_COL_; ++k) + { + types[k] = G_TYPE_STRING; + types[k + BIN_DEV_COL_] = G_TYPE_UINT; + } + + bindev->store = gtk_list_store_newv (BIN_DEV_COL_ * 2, types); + + dev->widget = + gtk_tree_view_new_with_model (GTK_TREE_MODEL (bindev->store)); + + gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (dev->widget), FALSE); + gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (dev->widget), TRUE); + + for (k = 0; k < BIN_DEV_COL_; ++k) + { + gtk_tree_view_append_column + (GTK_TREE_VIEW (dev->widget), + gtk_tree_view_column_new_with_attributes ("", renderer, + "text", k, NULL)); + } + + + g_free (types); + } + + g_assert (dev->widget); + gtk_container_add (GTK_CONTAINER (dev->scroll), dev->widget); + mixgtk_fontsel_set_font (MIX_FONT_DEVICES, dev->widget); + gtk_notebook_append_page (dev_nb_, dev->scroll, label); + gtk_widget_show (label); + gtk_widget_show (dev->scroll); + gtk_widget_show (dev->widget); +} + +static void +redraw_bin_device_ (struct mixgtk_bin_device_t *dev) +{ + if (dev != NULL) + { + GtkTreeModel *store = GTK_TREE_MODEL (dev->store); + GtkTreeIter iter; + gboolean valid; + + g_assert (store); + + valid = + gtk_tree_model_get_iter_first (store, &iter); + + while (valid) + { + gint k; + guint word; + + for (k = 0; k < BIN_DEV_COL_; ++k) + { + gtk_tree_model_get (store, &iter, k + BIN_DEV_COL_, &word, -1); + gtk_list_store_set (GTK_LIST_STORE (store), &iter, + k, get_word_string_ ((mix_word_t)word, + dev->dec), + -1); + } + valid = gtk_tree_model_iter_next (store, &iter); + } + gtk_widget_queue_draw (((struct mixgtk_device_t *)dev)->widget); + } +} + + +/* create a new mixgtk device */ +static mix_device_t * +mixgtk_device_new_ (mix_device_type_t type) +{ + struct mixgtk_device_t *dev = NULL; + + g_return_val_if_fail (type < mix_dev_INVALID, NULL); + + if (MODES_[type] == mix_dev_CHAR) + { + dev = g_new (struct mixgtk_device_t, 1); + } + else + { + dev = (struct mixgtk_device_t *) g_new (struct mixgtk_bin_device_t, 1); + ((struct mixgtk_bin_device_t *)dev)->last_insert = 0; + } + + construct_device_ (&dev->device, type); + + dev->device.vtable = &MIXGTK_VTABLE_; + + mixgtk_device_construct_gui_ (dev); + + return (mix_device_t *)dev; +} + +/* init default devices */ +GtkWidget * +mixgtk_device_init (mix_vm_t *vm) +{ + g_assert (vm != NULL); + + vm_ = vm; + devdlg_ = NULL; + devdir_dlg_ = NULL; + devdir_entry_ = NULL; + input_dlg_ = NULL; + dtoggle_ = NULL; + wtoggle_ = NULL; + combo_ = NULL; + + if (dev_nb_ == NULL) + { + mix_vm_set_device_factory (vm, mixgtk_device_new_); + + /* read format configuration */ + if (mixgtk_config_get (DEV_FORMAT_KEY_)) + decs_ = atoi (mixgtk_config_get (DEV_FORMAT_KEY_)); + + dev_nb_ = GTK_NOTEBOOK (gtk_notebook_new ()); + gtk_notebook_set_tab_pos (dev_nb_, GTK_POS_RIGHT); + gtk_notebook_set_scrollable (dev_nb_, FALSE); + } + + mixgtk_fontsel_set_font (MIX_FONT_DEVICES, GTK_WIDGET (dev_nb_)); + + return GTK_WIDGET (dev_nb_); +} + +void +mixgtk_device_set_format (mix_device_type_t dev, gboolean dec) +{ + gboolean changed; + + g_return_if_fail (dev < mix_dev_INVALID); + + changed = (dec && !IS_DEC (decs_, dev)) || (!dec && IS_DEC (decs_, dev)); + + if (changed && (MODES_[dev] == mix_dev_BIN)) + { + struct mixgtk_bin_device_t *gdev = + (struct mixgtk_bin_device_t *) mix_vm_get_device (vm_, dev); + + if (gdev != NULL) + { + if (dec) SET_DEC (decs_, dev); else CLEAR_DEC (decs_, dev); + gdev->dec = !(gdev->dec); + redraw_bin_device_ (gdev); + } + } +} + + +static mix_device_type_t +get_device_idx_ (void) +{ + int k; + const gchar *name = gtk_entry_get_text (GTK_ENTRY (GTK_BIN (combo_)->child)); + for (k = 0; k <= LAST_BIN_DEV_; ++k) + if (!strcmp (name, DEF_NAMES_[k])) break; + return k; +} + +static void +init_devform_ (void) +{ + devdlg_ = mixgtk_widget_factory_get_dialog (MIXGTK_DEVFORM_DIALOG); + g_assert (devdlg_); + dtoggle_ = mixgtk_widget_factory_get_child_by_name + (MIXGTK_DEVFORM_DIALOG, "decradio"); + g_assert (dtoggle_); + wtoggle_ = mixgtk_widget_factory_get_child_by_name + (MIXGTK_DEVFORM_DIALOG, "wordradio"); + g_assert (wtoggle_); + combo_ = mixgtk_widget_factory_get_child_by_name + (MIXGTK_DEVFORM_DIALOG, "dev_combo"); + g_assert (combo_); + gtk_editable_set_editable (GTK_EDITABLE (GTK_BIN (combo_)->child), FALSE); +} + +void +on_dev_combo_changed () +{ + mix_device_type_t dev = get_device_idx_ (); + if (dev <= LAST_BIN_DEV_) + { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dtoggle_), + IS_DEC (new_decs_, dev)); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (wtoggle_), + !IS_DEC (new_decs_, dev)); + } +} + +void +on_devform_activate () +{ + gint result = GTK_RESPONSE_APPLY; + + if (!devdlg_) init_devform_ (); + new_decs_ = decs_; + + while (result == GTK_RESPONSE_APPLY) + { + //on_dev_combo_changed (); + result = gtk_dialog_run (GTK_DIALOG (devdlg_)); + if (result != GTK_RESPONSE_CANCEL) + { + int k; + gchar value[20]; + for (k = 0; k <= LAST_BIN_DEV_; ++k) + mixgtk_device_set_format (k, IS_DEC (new_decs_, k)); + decs_ = new_decs_; + g_snprintf (value, 20, "%d", decs_); + mixgtk_config_update (DEV_FORMAT_KEY_, value); + } + } + + gtk_widget_hide (devdlg_); +} + +void +on_decradio_toggled (GtkToggleButton *button) +{ + if (gtk_toggle_button_get_active (button)) + SET_DEC (new_decs_, get_device_idx_ ()); + else + CLEAR_DEC (new_decs_, get_device_idx_ ()); +} + +void +on_devset_button_clicked () +{ + static gint32 ON = 0xffff, OFF = 0; + new_decs_ = (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dtoggle_)))? + ON : OFF; +} + +void +on_devdir_activate () +{ + static const gchar *DEVDIR_ENTRY_NAME = "devdir_entry"; + if (devdir_dlg_ == NULL) + { + devdir_dlg_ = mixgtk_widget_factory_get_dialog (MIXGTK_DEVDIR_DIALOG); + g_assert (devdir_dlg_); + devdir_entry_ = GTK_ENTRY + (mixgtk_widget_factory_get_child_by_name (MIXGTK_DEVDIR_DIALOG, + DEVDIR_ENTRY_NAME)); + g_assert (devdir_entry_); + } + gtk_entry_set_text (devdir_entry_, mix_device_get_dir ()); + gtk_widget_show (devdir_dlg_); +} + +void +on_devdir_browse_clicked () +{ + GtkWidget *dialog; + const gchar *current = gtk_entry_get_text (devdir_entry_); + + dialog = + gtk_file_chooser_dialog_new (_("Devices folder"), + GTK_WINDOW (devdir_dlg_), + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, + NULL); + + if (current != NULL) + gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), current); + + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) + { + char *filename + = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); + gtk_entry_set_text (devdir_entry_, filename); + g_free (filename); + } + + gtk_widget_destroy (dialog); +} + +void +on_devdir_cancel_clicked () +{ + gtk_widget_hide (devdir_dlg_); +} + +void +on_devdir_ok_clicked () +{ + const gchar *dirname = gtk_entry_get_text (devdir_entry_); + gchar *cmd = g_strconcat (mix_vm_command_to_string (MIX_CMD_SDDIR), + " ", dirname, NULL); + gtk_widget_hide (devdir_dlg_); + mixgtk_cmd_dispatcher_dispatch (cmd); + g_free (cmd); +} + + + +/* fonts */ +static GtkWidget ** +font_widgets_ (gint * n) +{ + gint no = gtk_notebook_get_n_pages (dev_nb_); + GtkWidget **w = g_new (GtkWidget *, no + 1); + gint k, j; + + for (k = 0, j = 0; k < no && j < mix_dev_INVALID; ++j) + { + struct mixgtk_device_t * dev = + (struct mixgtk_device_t *) mix_vm_get_device (vm_, j); + if (dev != NULL) w[k++] = dev->widget; + } + + g_assert (k == no); + w[k] = GTK_WIDGET (dev_nb_); + + if (n) *n = no; + + return w; +} + +void +on_devices_font_activate () +{ + gint no = 0; + GtkWidget **w = font_widgets_ (&no); + mixgtk_fontsel_query_font (MIX_FONT_DEVICES, w, no + 1); + g_free (w); +} + +void +mixgtk_device_update_fonts (void) +{ + gint k, n = 0; + GtkWidget **w = font_widgets_ (&n); + + g_assert (n >= 0); + + for (k = 0; k < n; ++k) + mixgtk_fontsel_set_font (MIX_FONT_DEVICES, w[k]); +} diff --git a/mixgtk/mixgtk_device.h b/mixgtk/mixgtk_device.h new file mode 100644 index 0000000..69859f3 --- /dev/null +++ b/mixgtk/mixgtk_device.h @@ -0,0 +1,45 @@ +/* -*-c-*- ---------------- mixgtk_device.h : + * Block devices used by mixgtk + * ------------------------------------------------------------------ + * Last change: Time-stamp: <01/03/04 23:43:59 jose> + * ------------------------------------------------------------------ + * Copyright (C) 2001, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + + +#ifndef MIXGTK_DEVICE_H +#define MIXGTK_DEVICE_H + +#include +#include +#include + +/* init default devices */ +extern GtkWidget * +mixgtk_device_init (mix_vm_t *vm); + +extern void +mixgtk_device_update_fonts (void); + +/* change the output format of a device */ +extern void +mixgtk_device_set_format (mix_device_type_t dev, gboolean dec); + + +#endif /* MIXGTK_DEVICE_H */ + diff --git a/mixgtk/mixgtk_fontsel.c b/mixgtk/mixgtk_fontsel.c new file mode 100644 index 0000000..e88793b --- /dev/null +++ b/mixgtk/mixgtk_fontsel.c @@ -0,0 +1,142 @@ +/* -*-c-*- -------------- mixgtk_fontsel.c : + * Implementation of the functions declared in mixgtk_fontsel.h + * ------------------------------------------------------------------ + * $Id: mixgtk_fontsel.c,v 1.19 2005/09/20 19:43:14 jao Exp $ + * ------------------------------------------------------------------ + * Copyright (C) 2001, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include +#include "mixgtk_widgets.h" +#include "mixgtk_config.h" +#include "mixgtk_mixvm.h" +#include "mixgtk_mixal.h" +#include "mixgtk_cmd_dispatcher.h" +#include "mixgtk_device.h" +#include "mixgtk_fontsel.h" + +static GtkFontSelectionDialog *fontsel_dialog_ = NULL; + +static const gchar *keys_[MIX_FONT_NO] = { + "MIX.font", "Prompt.font", "Log.font", "MIXAL.font", "Devices.font", + "Symbols.font", "Default.font" +}; + + +/* initialise the font selection dialog */ +static void +init_fontsel_ (void) +{ + fontsel_dialog_ = + GTK_FONT_SELECTION_DIALOG + (mixgtk_widget_factory_get_dialog (MIXGTK_FONTSEL_DIALOG)); + g_assert (fontsel_dialog_ != NULL); +} + +void +mixgtk_fontsel_set_font (mixgtk_font_t f, GtkWidget *w) +{ + const gchar *font; + PangoFontDescription *font_desc; + + if (f >= MIX_FONT_NO || w == NULL) return; + + font = mixgtk_config_get (keys_[f]); + if (!font) + { + mixgtk_config_update (keys_[f], "Monospace 10"); + font = mixgtk_config_get (keys_[f]); + g_assert (font); + } + + font_desc = pango_font_description_from_string (font); + + if (font_desc) + { + gtk_widget_modify_font (w, font_desc); + gtk_widget_queue_draw (w); + pango_font_description_free (font_desc); + } + else + mixgtk_config_remove (keys_[f]); + +} + +gboolean +mixgtk_fontsel_query_font (mixgtk_font_t f, GtkWidget **w, size_t no) +{ + gint result = GTK_RESPONSE_APPLY; + const gchar *current; + gboolean ret = FALSE; + + if (f >= MIX_FONT_NO) return FALSE; + if (!fontsel_dialog_) init_fontsel_ (); + + current = mixgtk_config_get (keys_[f]); + gtk_font_selection_dialog_set_font_name (fontsel_dialog_, + current? current : "Monospace 10"); + + 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; +} + +void +on_all_fonts_activate (void) +{ + gint result = GTK_RESPONSE_APPLY; + const gchar *current; + + if (!fontsel_dialog_) init_fontsel_ (); + + current = mixgtk_config_get (keys_[MIX_FONT_DEFAULT]); + gtk_font_selection_dialog_set_font_name (fontsel_dialog_, + current? current : "Monospace"); + + while (result == GTK_RESPONSE_APPLY) + { + result = gtk_dialog_run (GTK_DIALOG (fontsel_dialog_)); + if (result != GTK_RESPONSE_CANCEL) + { + gint k; + current = gtk_font_selection_dialog_get_font_name (fontsel_dialog_); + + for (k = 0; k < MIX_FONT_NO; ++k) + mixgtk_config_update (keys_[k], current); + + mixgtk_mixal_update_fonts (); + mixgtk_mixvm_update_fonts (); + mixgtk_device_update_fonts (); + mixgtk_cmd_dispatcher_update_fonts (); + } + } + gtk_widget_hide (GTK_WIDGET (fontsel_dialog_)); +} diff --git a/mixgtk/mixgtk_fontsel.h b/mixgtk/mixgtk_fontsel.h new file mode 100644 index 0000000..2228ed6 --- /dev/null +++ b/mixgtk/mixgtk_fontsel.h @@ -0,0 +1,51 @@ +/* -*-c-*- ---------------- mixgtk_fontsel.h : + * Functions for handling font selection. + * ------------------------------------------------------------------ + * $Id: mixgtk_fontsel.h,v 1.8 2005/09/20 19:43:14 jao Exp $ + * ------------------------------------------------------------------ + * Copyright (C) 2001, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + + +#ifndef MIXGTK_FONTSEL_H +#define MIXGTK_FONTSEL_H + +#include +#include "mixgtk_widgets.h" + +typedef enum { + MIX_FONT_MIXVM, + MIX_FONT_LOG, + MIX_FONT_PROMPT, + MIX_FONT_MIXAL, + MIX_FONT_DEVICES, + MIX_FONT_SYMBOLS, + MIX_FONT_DEFAULT, + MIX_FONT_NO +} mixgtk_font_t; + +/* configured fonts */ +extern void +mixgtk_fontsel_set_font (mixgtk_font_t f, GtkWidget *w); + +extern gboolean +mixgtk_fontsel_query_font (mixgtk_font_t f, GtkWidget **ws, size_t no); + + +#endif /* MIXGTK_FONTSEL_H */ + diff --git a/mixgtk/mixgtk_gen_handlers.c b/mixgtk/mixgtk_gen_handlers.c new file mode 100644 index 0000000..151feac --- /dev/null +++ b/mixgtk/mixgtk_gen_handlers.c @@ -0,0 +1,165 @@ +/* -*-c-*- -------------- mixgtk_gen_handlers.c : + * Implementation of the functions declared in mixgtk_gen_handlers.h + * ------------------------------------------------------------------ + * $Id: mixgtk_gen_handlers.c,v 1.10 2005/09/20 19:43:14 jao Exp $ + * ------------------------------------------------------------------ + * Copyright (C) 2001, 2002, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include +#include "mixgtk_gen_handlers.h" +#include "mixgtk_cmd_dispatcher.h" +#include "mixgtk_config.h" + +/* grab a file with an externally provided callback */ +void +mixgtk_get_file (file_callback_t callback, + const gchar *title, + const gchar *pattern, + const gchar *def_file) +{ + if (callback != NULL) + { + GtkWidget *dialog; + + dialog = + gtk_file_chooser_dialog_new (title, + NULL, + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, + NULL); + + if (pattern != NULL) + { + GtkFileFilter *filter = gtk_file_filter_new (); + gtk_file_filter_add_pattern (filter, pattern); + gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter); + } + + if (def_file != NULL) + gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), def_file); + + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) + { + char *filename; + + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); + callback (filename); + g_free (filename); + } + + gtk_widget_destroy (dialog); + } +} + +/* exec prompt command */ +static void +exec_cmd_ (mix_vm_command_t cmd, const gchar *arg) +{ + gchar *command; + if (arg) + command = g_strdup_printf ("%s %s", + mix_vm_command_to_string (cmd), + arg); + else + command = g_strdup (mix_vm_command_to_string (cmd)); + mixgtk_cmd_dispatcher_dispatch (command); + g_free (command); +} + +/* load mix binary */ +static void +open_cb_ (const gchar *file) +{ + if (file) + exec_cmd_ (MIX_CMD_LOAD, file); +} + +void +on_file_open_activate (GtkWidget *w, gpointer data) +{ + mixgtk_get_file (open_cb_, _("Load MIX program..."), "*.mix", NULL); +} + +/* edit mixal source */ +static void +edit_cb_ (const gchar *file) +{ + exec_cmd_ (MIX_CMD_EDIT, file); +} + +void +on_file_edit_activate (GtkWidget *w, gpointer data) +{ + mixgtk_get_file (edit_cb_, _("Edit MIXAL source file..."), "*.mixal", + mixgtk_cmd_dispatcher_get_src_path ()); +} + +/* compile mixal source */ +static void +compile_cb_ (const gchar *file) +{ + exec_cmd_ (MIX_CMD_COMPILE, file); +} + +void +on_file_compile_activate (GtkWidget *w, gpointer data) +{ + mixgtk_get_file (compile_cb_, _("Compile MIXAL source file..."), "*.mixal", + mixgtk_cmd_dispatcher_get_src_path ()); +} + +void +on_debug_run_activate (GtkWidget *w, gpointer p) +{ + mixgtk_cmd_dispatcher_dispatch (mix_vm_command_to_string (MIX_CMD_RUN)); +} + +void +on_debug_next_activate (GtkWidget *w, gpointer p) +{ + mixgtk_cmd_dispatcher_dispatch (mix_vm_command_to_string (MIX_CMD_NEXT)); +} + + +void +on_file_exit_activate (GtkWidget *w, gpointer data) +{ + gtk_main_quit (); +} + +void +on_clear_breakpoints_activate (GtkWidget *w, gpointer data) +{ + mixgtk_cmd_dispatcher_dispatch (mix_vm_command_to_string (MIX_CMD_CABP)); +} + +void +on_save_on_exit_toggle (GtkWidget *w, gpointer data) +{ + mixgtk_config_set_autosave (GTK_CHECK_MENU_ITEM (w)->active); +} + +void +on_save_activate (GtkWidget *w, gpointer data) +{ + mixgtk_config_save (); +} + + diff --git a/mixgtk/mixgtk_gen_handlers.h b/mixgtk/mixgtk_gen_handlers.h new file mode 100644 index 0000000..c82c195 --- /dev/null +++ b/mixgtk/mixgtk_gen_handlers.h @@ -0,0 +1,62 @@ +/* -*-c-*- ---------------- mixgtk_gen_handlers.h : + * general signal handlers declarations + * ------------------------------------------------------------------ + * $Id: mixgtk_gen_handlers.h,v 1.7 2005/09/20 19:43:14 jao Exp $ + * ------------------------------------------------------------------ + * Copyright (C) 2001, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + + +#ifndef MIXGTK_GEN_HANDLERS_H +#define MIXGTK_GEN_HANDLERS_H + +#include + +extern void +on_main_window_destroy (GtkWidget *w, gpointer data); + +extern void +on_file_open_activate (GtkWidget *w, gpointer data); + +extern void +on_file_exit_activate (GtkWidget *w, gpointer data); + +extern void +on_file_edit_activate (GtkWidget *w, gpointer data); + +extern void +on_file_compile_activate (GtkWidget *w, gpointer data); + +extern void +on_clear_breakpoints_activate (GtkWidget *w, gpointer data); + +extern void +on_save_on_exit_toggle (GtkWidget *w, gpointer data); + +extern void +on_save_activate (GtkWidget *w, gpointer data); + +typedef void (*file_callback_t)(const gchar *file); + +extern void +mixgtk_get_file (file_callback_t callback, const gchar *title, + const gchar *pattern, const gchar *def_file); + + +#endif /* MIXGTK_GEN_HANDLERS_H */ + diff --git a/mixgtk/mixgtk_input.c b/mixgtk/mixgtk_input.c new file mode 100644 index 0000000..238fadd --- /dev/null +++ b/mixgtk/mixgtk_input.c @@ -0,0 +1,233 @@ +/* -*-c-*- -------------- mixgtk_input.c : + * Implementation of the functions declared in mixgtk_input.h + * ------------------------------------------------------------------ + * $Id: mixgtk_input.c,v 1.7 2005/09/20 19:43:14 jao Exp $ + * ------------------------------------------------------------------ + * Copyright (C) 2001, 2002, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include +#include +#include + +#include "mixgtk_widgets.h" +#include "mixgtk_input.h" + +enum { + MSG_, SIGN_, B1_, B2_, B3_, B4_, B5_, DEC_, RESET_, OK_, SIZE_ +}; + +static const gchar *WGT_NAMES_[SIZE_] = { + "word_label", "word_sign", "word_b1", "word_b2", "word_b3", + "word_b4", "word_b5", "word_decimal", "word_reset", "word_ok" +}; + +static GtkDialog *dialog_ = NULL; +static GtkWidget *childs_[SIZE_]; +static input_callback_t callback_; +static gpointer data_; + + +static void init_dialog_ (void); +static void set_word_ (mix_word_t word); + + +/* init */ +void +mixgtk_input_init (void) +{ + dialog_ = NULL; +} + +/* get a word */ +void +mixgtk_input_word (const gchar *message, mix_word_t def, + input_callback_t cb, gpointer data) +{ + if (!dialog_) init_dialog_ (); + gtk_label_set_text (GTK_LABEL (childs_[MSG_]), message); + set_word_ (def); + callback_ = cb; + data_ = data; + gtk_widget_show (childs_[B1_]); + gtk_widget_show (childs_[B2_]); + gtk_widget_show (childs_[B3_]); + gtk_widget_show (GTK_WIDGET (dialog_)); +} + +/* get a short */ +void +mixgtk_input_short (const gchar *message, mix_short_t def, + input_callback_t cb, gpointer data) +{ + if (!dialog_) init_dialog_ (); + gtk_label_set_text (GTK_LABEL (childs_[MSG_]), message); + set_word_ (mix_word_to_short_fast (def)); + callback_ = cb; + data_ = data; + gtk_widget_show (GTK_WIDGET (dialog_)); + gtk_widget_hide (childs_[B1_]); + gtk_widget_hide (childs_[B2_]); + gtk_widget_hide (childs_[B3_]); +} + +#include + +/* dec and bytes input handler */ +void +on_word_dec_changed (GtkEditable *dec, gpointer *data) +{ + gchar *txt = gtk_editable_get_chars (dec, 0, -1); + + if (strlen (txt) > 0) + { + gint val = atoi (txt); + set_word_ (mix_word_new (val)); + } + g_free (txt); +} + +void +on_word_byte_changed (GtkEditable *byte, gpointer *data) +{ + gchar *txt = gtk_editable_get_chars (byte, 0, 2); + + if (strlen (txt) > 0) + { + mix_byte_t bytes[5]; + gint k; + const gchar *s; + mix_word_t w; + + for (k = 0; k < 5; ++k) + { + const gchar *text = gtk_entry_get_text (GTK_ENTRY (childs_[B1_ + k])); + bytes[k] = mix_byte_new (atoi (text)); + } + w = mix_bytes_to_word (bytes, 5); + s = gtk_entry_get_text (GTK_ENTRY (childs_[SIGN_])); + if (s && s[0] == '-') mix_word_reverse_sign (w); + set_word_ (w); + } + g_free (txt); +} + +void +on_word_sign_changed (GtkEditable *sign, gpointer *data) +{ + gchar *txt = gtk_editable_get_chars (sign, 0, 1); + + if (strlen (txt) > 0) + { + gint pos = 0; + mix_word_t w = + mix_word_new (atoi (gtk_entry_get_text (GTK_ENTRY (childs_[DEC_])))); + + g_signal_handlers_block_by_func (GTK_OBJECT (sign), + on_word_sign_changed, data); + + if (txt[0] != '+' && txt[0] != '-') txt[0] = '+'; + gtk_editable_delete_text (sign, 0, 1); + gtk_editable_insert_text (sign, txt, 1, &pos); + + g_signal_handlers_unblock_by_func (GTK_OBJECT (sign), + on_word_sign_changed, data); + set_word_ (txt[0] == '-' ? mix_word_negative (w) : w); + } + g_free (txt); +} + +void +on_word_ok_clicked (GtkWidget *widget, gpointer *data) +{ + const gchar *text = gtk_entry_get_text (GTK_ENTRY (childs_[DEC_])); + mix_word_t w = mix_word_new (atoi (text)); + if (w == MIX_WORD_ZERO) + { + const gchar *sign = gtk_entry_get_text (GTK_ENTRY (childs_[SIGN_])); + if (sign && sign[0] == '-') mix_word_reverse_sign (w); + } + callback_ (w, data_); + gtk_widget_hide (GTK_WIDGET (dialog_)); +} + +void +on_word_cancel_clicked (GtkWidget *widget, gpointer *data) +{ + gtk_widget_hide (GTK_WIDGET (dialog_)); +} + +void +on_word_reset_clicked (GtkWidget *w, gpointer *data) +{ + set_word_ (MIX_WORD_ZERO); +} + +static void +init_dialog_ (void) +{ + gint k; + + dialog_ = GTK_DIALOG (mixgtk_widget_factory_get_dialog (MIXGTK_WORD_DIALOG)); + g_assert (dialog_ != NULL); + for (k = 0; k < SIZE_; ++k) + { + childs_[k] = mixgtk_widget_factory_get_child_by_name + (MIXGTK_WORD_DIALOG, WGT_NAMES_[k]); + g_assert (childs_[k] != NULL); + } +} + +static void +set_word_ (mix_word_t word) +{ + enum {SIZE = 50}; + static gchar BUFFER[SIZE] = {0}; + gint k; + gint val = mix_word_magnitude (word); + gboolean neg = mix_word_is_negative (word); + g_snprintf (BUFFER, SIZE, "%s%d", neg ? "-" : "", val); + + + g_signal_handlers_block_by_func (GTK_OBJECT (childs_[DEC_]), + on_word_dec_changed, NULL); + g_signal_handlers_block_by_func (GTK_OBJECT (childs_[SIGN_]), + on_word_sign_changed, NULL); + for (k = B1_; k <= B5_; ++k) + g_signal_handlers_block_by_func (GTK_OBJECT (childs_[k]), + on_word_byte_changed, NULL); + + gtk_entry_set_text (GTK_ENTRY (childs_[DEC_]), BUFFER); + gtk_entry_set_text (GTK_ENTRY (childs_[SIGN_]), neg ? "-" : "+"); + + for (k = 1; k < 6; ++k) + { + mix_byte_t b = mix_word_get_byte (word, k); + g_snprintf (BUFFER, SIZE, "%d", (int)b); + gtk_entry_set_text (GTK_ENTRY (childs_[SIGN_ + k]), BUFFER); + } + + for (k = B1_; k <= B5_; ++k) + g_signal_handlers_unblock_by_func (GTK_OBJECT (childs_[k]), + on_word_byte_changed, NULL); + g_signal_handlers_unblock_by_func (GTK_OBJECT (childs_[DEC_]), + on_word_dec_changed, NULL); + g_signal_handlers_unblock_by_func (GTK_OBJECT (childs_[SIGN_]), + on_word_sign_changed, NULL); +} + diff --git a/mixgtk/mixgtk_input.h b/mixgtk/mixgtk_input.h new file mode 100644 index 0000000..924e90b --- /dev/null +++ b/mixgtk/mixgtk_input.h @@ -0,0 +1,49 @@ +/* -*-c-*- ---------------- mixgtk_input.h : + * Declaration of functions for user input + * ------------------------------------------------------------------ + * Last change: Time-stamp: <01/03/12 23:35:14 jose> + * ------------------------------------------------------------------ + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + + +#ifndef MIXGTK_INPUT_H +#define MIXGTK_INPUT_H + +#include + +/* callback function type */ +typedef void (*input_callback_t)(mix_word_t result, gpointer data); + +/* init */ +extern void +mixgtk_input_init (void); + +/* get a word */ +extern void +mixgtk_input_word (const gchar *message, mix_word_t def, + input_callback_t cb, gpointer data); + +/* get a short */ +extern void +mixgtk_input_short (const gchar *message, mix_short_t def, + input_callback_t cb, gpointer data ); + + +#endif /* MIXGTK_INPUT_H */ + diff --git a/mixgtk/mixgtk_mixal.c b/mixgtk/mixgtk_mixal.c new file mode 100644 index 0000000..50d09a7 --- /dev/null +++ b/mixgtk/mixgtk_mixal.c @@ -0,0 +1,580 @@ +/* -*-c-*- -------------- mixgtk_mixal.c : + * Implementation of the functions declared in mixgtk_mixal.h + * ------------------------------------------------------------------ + * $Id: mixgtk_mixal.c,v 1.22 2005/09/20 19:43:14 jao Exp $ + * ------------------------------------------------------------------ + * Copyright (C) 2001, 2002, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + + +#include +#include + +#include "mixgtk_widgets.h" +#include "mixgtk_config.h" +#include "mixgtk_fontsel.h" +#include "mixgtk_mixal.h" + +static mix_vm_t *vm_ = NULL; +static GtkTreeView *clist_ = NULL; +static GtkListStore *clist_store_ = NULL; + +static gulong lineno_; +static GtkStatusbar *status_ = NULL; +static gint status_context_ = 0; +static GPtrArray *tips_text_ = NULL; + +static GtkWidget *symbols_dlg_ = NULL; +static GtkTreeView *symbols_view_ = NULL; +static GtkListStore *symbols_store_ = NULL; +static const gchar *SYMBOLS_VIEW_NAME_ = "symbols_view"; + +static const gchar *bp_stock_id_ = NULL; +static const gchar *pc_stock_id_ = NULL; +static const guint bp_stock_size_ = GTK_ICON_SIZE_MENU; + +enum { + CLIST_BP_ID_COL, + CLIST_BP_SIZE_COL, + CLIST_ADDRESS_COL, + CLIST_BYTECODE_COL, + CLIST_CODE_COL, + CLIST_ADDRESS_NO_COL, + CLIST_LINE_NO_COL, + CLIST_COL_NO +}; + +enum { + SYMBOLS_NAME_COL, + SYMBOLS_VALUE_COL, + SYMBOLS_WORD_COL, + SYMBOLS_COL_NO +}; + + +static gboolean +mixal_event_ (GtkWidget *w, GdkEvent *event, gpointer data); + + +static void +init_symbols_ (void) +{ + GtkCellRenderer *renderer = gtk_cell_renderer_text_new (); + + symbols_dlg_ = mixgtk_widget_factory_get_dialog (MIXGTK_SYMBOLS_DIALOG); + g_assert (symbols_dlg_); + symbols_view_ = GTK_TREE_VIEW + (mixgtk_widget_factory_get_child_by_name + (MIXGTK_SYMBOLS_DIALOG, SYMBOLS_VIEW_NAME_)); + g_assert (symbols_view_); + + mixgtk_fontsel_set_font (MIX_FONT_SYMBOLS, GTK_WIDGET (symbols_view_)); + + symbols_store_ = gtk_list_store_new (SYMBOLS_COL_NO, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_STRING); + + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (symbols_store_), + SYMBOLS_NAME_COL, + GTK_SORT_ASCENDING); + + gtk_tree_view_set_model (symbols_view_, GTK_TREE_MODEL (symbols_store_)); + g_object_unref (G_OBJECT (symbols_store_)); + gtk_tree_view_append_column + (symbols_view_, + gtk_tree_view_column_new_with_attributes ("Name", renderer, + "text", SYMBOLS_NAME_COL, + NULL)); + gtk_tree_view_append_column + (symbols_view_, + gtk_tree_view_column_new_with_attributes ("Value", renderer, + "text", SYMBOLS_VALUE_COL, + NULL)); + gtk_tree_view_append_column + (symbols_view_, + gtk_tree_view_column_new_with_attributes ("", renderer, + "text", SYMBOLS_WORD_COL, + NULL)); +} + +static void +insert_symbol_ (gpointer symbol, gpointer value, gpointer data) +{ + enum {DEC_SIZE = 25, WORD_SIZE = 20}; + static gchar DEC[DEC_SIZE], WORD[WORD_SIZE]; + + GtkTreeIter iter; + + mix_word_t w = (mix_word_t)GPOINTER_TO_INT (value); + g_snprintf (DEC, DEC_SIZE, "%s%ld", + mix_word_is_negative (w)? "-" : "+", + mix_word_magnitude (w)); + mix_word_print_to_buffer (w, WORD); + + gtk_list_store_append (symbols_store_, &iter); + gtk_list_store_set (symbols_store_, &iter, + SYMBOLS_NAME_COL, (const gchar*)symbol, + SYMBOLS_VALUE_COL, DEC, + SYMBOLS_WORD_COL, WORD, + -1); +} + +static void +fill_symbols_ (const mix_symbol_table_t *table) +{ + if (symbols_view_) + gtk_list_store_clear (symbols_store_); + else + init_symbols_ (); + + mix_symbol_table_foreach (((mix_symbol_table_t *)table), + insert_symbol_, NULL); +} + +static void +init_clist_ (void) +{ + GtkStockItem item; + + GtkCellRenderer *renderer = gtk_cell_renderer_text_new (); + GtkCellRenderer *bprenderer = gtk_cell_renderer_pixbuf_new (); + + clist_ = GTK_TREE_VIEW (gtk_tree_view_new ()); + + clist_store_ = gtk_list_store_new (CLIST_COL_NO, + G_TYPE_STRING, + G_TYPE_INT, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_INT, + G_TYPE_INT); + + gtk_tree_view_set_model (clist_, GTK_TREE_MODEL (clist_store_)); + g_object_unref (G_OBJECT (clist_store_)); + gtk_tree_view_set_rules_hint (clist_, TRUE); + + gtk_tree_view_append_column + (clist_, + gtk_tree_view_column_new_with_attributes ("", bprenderer, + "stock-id", CLIST_BP_ID_COL, + "stock-size", CLIST_BP_SIZE_COL, + NULL)); + gtk_tree_view_append_column + (clist_, + gtk_tree_view_column_new_with_attributes ("Address", renderer, + "text", CLIST_ADDRESS_COL, + NULL)); + gtk_tree_view_append_column + (clist_, + gtk_tree_view_column_new_with_attributes ("Bytecode", renderer, + "text", CLIST_BYTECODE_COL, + NULL)); + gtk_tree_view_append_column + (clist_, + gtk_tree_view_column_new_with_attributes ("Source", renderer, + "text", CLIST_CODE_COL, + NULL)); + + if (gtk_stock_lookup (GTK_STOCK_STOP, &item)) + { + bp_stock_id_ = item.stock_id; + } + + if (gtk_stock_lookup (GTK_STOCK_GO_FORWARD, &item)) + { + pc_stock_id_ = item.stock_id; + } + + symbols_dlg_ = NULL; + symbols_view_ = NULL; + + g_signal_connect (G_OBJECT (clist_), "event", + G_CALLBACK (mixal_event_), NULL); + + + mixgtk_fontsel_set_font (MIX_FONT_MIXAL, GTK_WIDGET (clist_)); + + gtk_widget_show (GTK_WIDGET (clist_)); + +} + + +/* initialise the mixal widgets */ +GtkWidget * +mixgtk_mixal_init (mix_vm_t *vm) +{ + if (vm != NULL) vm_ = vm; + + if (vm_ == NULL) return FALSE; + + if (clist_ == NULL) init_clist_ (); + + status_ = NULL; + + return GTK_WIDGET (clist_); +} + +void +mixgtk_mixal_reparent (GtkStatusbar *status) +{ + g_assert (status != NULL); + mixgtk_mixal_pop_status (); + status_ = status; + status_context_ = gtk_statusbar_get_context_id (status_, "MIXAL status"); +} + +void +mixgtk_mixal_update_fonts (void) +{ + mixgtk_fontsel_set_font (MIX_FONT_MIXAL, GTK_WIDGET (clist_)); + mixgtk_fontsel_set_font (MIX_FONT_SYMBOLS, GTK_WIDGET (symbols_view_)); +} + +void +mixgtk_mixal_pop_status (void) +{ + if (status_ != NULL) + gtk_statusbar_pop (status_, status_context_); +} + +/* load the corresponding mixal file */ +static void +update_tips_ (const mix_symbol_table_t *table, + const gchar *line) +{ + enum {SIZE = 256}; + static gchar BUFFER[256]; + static const gchar *DELIMITERS = " /+*=-()\t,:\n"; + if (line) + { + guint k = 0; + gchar *tip = g_strdup (""); + gchar *new_tip; + gchar **tokens; + gchar *text = g_strdup (line); + text = g_strdelimit (text, DELIMITERS, ' '); + tokens = g_strsplit (g_strstrip (text), " ", -1); + while (tokens[k]) + { + if (mix_symbol_table_is_defined (table, tokens[k])) + { + mix_word_t val = mix_symbol_table_value (table, tokens[k]); + g_snprintf (BUFFER, SIZE, "[ %s = %s%ld ]", tokens[k], + mix_word_is_negative (val)? "-" : "+", + mix_word_magnitude (val)); + new_tip = g_strconcat (tip, " ", BUFFER, NULL); + g_free (tip); + tip = new_tip; + } + ++k; + } + g_ptr_array_add (tips_text_, (gpointer)tip); + g_strfreev (tokens); + g_free (text); + } +} + +void +mixgtk_mixal_load_file (void) +{ + enum {ADDR_SIZE = 20, CONT_SIZE = 200, WORD_SIZE = 20}; + static gchar ADDR[ADDR_SIZE], CONT[CONT_SIZE], WORD[WORD_SIZE]; + + const mix_src_file_t *file; + GtkTreeIter iter; + + g_assert (vm_); + g_assert (clist_); + + gtk_list_store_clear (clist_store_); + if (tips_text_) + { + g_ptr_array_free (tips_text_, TRUE); + tips_text_ = NULL; + } + + file = mix_vm_get_src_file (vm_); + if (file != NULL) + { + gint k; + + mix_address_t addr; + const mix_symbol_table_t *table = mix_vm_get_symbol_table (vm_); + + if (table) tips_text_ = g_ptr_array_new (); + + lineno_ = mix_src_file_get_line_no (file); + + for (k = 0; k < lineno_; ++k) + { + gchar *line = + g_strchomp ((gchar *)mix_src_file_get_line (file, k + 1)); + + g_snprintf (CONT, CONT_SIZE, " %03d: %s", k + 1, line); + addr = mix_vm_get_lineno_address (vm_, k + 1); + if (addr != MIX_VM_CELL_NO) + { + g_snprintf (ADDR, ADDR_SIZE, "%04d", mix_short_magnitude (addr)); + mix_word_print_to_buffer (mix_vm_get_addr_contents (vm_, addr), + WORD); + } + else + { + g_snprintf (ADDR, ADDR_SIZE, _("N/A")); + g_snprintf (WORD, WORD_SIZE, _("N/A")); + } + gtk_list_store_append (clist_store_, &iter); + gtk_list_store_set (clist_store_, &iter, + CLIST_ADDRESS_NO_COL, mix_short_magnitude (addr), + CLIST_LINE_NO_COL, k + 1, + CLIST_ADDRESS_COL, ADDR, + CLIST_CODE_COL, CONT, + CLIST_BYTECODE_COL, WORD, + CLIST_BP_SIZE_COL, bp_stock_size_, + -1); + if (table) update_tips_ (table, line); + } + if (table) fill_symbols_ (table); + } + else + { + lineno_ = 0; + gtk_list_store_append (clist_store_, &iter); + gtk_list_store_set (clist_store_, &iter, + CLIST_ADDRESS_NO_COL, MIX_VM_CELL_NO, + CLIST_LINE_NO_COL, 0, + CLIST_ADDRESS_COL, "", + CLIST_CODE_COL, _("Source not available"), + CLIST_BYTECODE_COL, "", + -1); + } +} + + +/* update the widgets */ +static gint +find_address_ (gint address) +{ + GtkTreeIter iter; + gint addr; + gint row = 0; + gboolean valid = + gtk_tree_model_get_iter_first (GTK_TREE_MODEL (clist_store_), &iter); + + while (valid) + { + ++row; + gtk_tree_model_get (GTK_TREE_MODEL (clist_store_), &iter, + CLIST_ADDRESS_NO_COL, &addr, -1); + if (addr == address) return row; + valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (clist_store_), &iter); + } + return 0; +} + +static void +update_bp_ (gint row) +{ + if (row > 0) + { + GtkTreePath *path = gtk_tree_path_new_from_indices (row - 1, -1); + GtkTreeIter iter; + + if (gtk_tree_model_get_iter (GTK_TREE_MODEL (clist_store_), &iter, path)) + { + gint address; + const gchar *id = NULL; + + gtk_tree_model_get (GTK_TREE_MODEL (clist_store_), &iter, + CLIST_ADDRESS_NO_COL, &address, -1); + if (mix_vm_has_breakpoint_at_address (vm_, address)) + id = bp_stock_id_; + else if (address == + (gint) mix_short_magnitude (mix_vm_get_prog_count (vm_))) + id = pc_stock_id_; + + gtk_list_store_set (clist_store_, &iter, CLIST_BP_ID_COL, id, -1); + } + gtk_tree_path_free (path); + } +} + +static void +select_row_ (gint row) +{ + static gint previous = 0; + + if (row > 0 && previous != row) + { + GtkTreePath *path = gtk_tree_path_new_from_indices (row - 1, -1); + GtkTreeIter iter; + + if (gtk_tree_model_get_iter (GTK_TREE_MODEL (clist_store_), &iter, path)) + { + gtk_list_store_set (clist_store_, &iter, + CLIST_BP_ID_COL, pc_stock_id_, + -1); + update_bp_ (previous); + previous = row; + gtk_tree_view_scroll_to_cell (clist_, path, NULL, FALSE, 0.3, 0); + } + gtk_tree_path_free (path); + } +} + +void +mixgtk_mixal_update (void) +{ + gint addr = 0; + + g_assert (vm_); + + addr = (gint) mix_short_magnitude (mix_vm_get_prog_count (vm_)); + select_row_ (find_address_ (addr)); +} + +/* breakpoints */ +void +mixgtk_mixal_update_bp_at_address (guint addr) +{ + update_bp_ (find_address_ ((gint)addr)); +} + +void +mixgtk_mixal_update_bp_at_line (guint line) +{ + update_bp_ ((gint)line); +} + +void +mixgtk_mixal_update_bp_all (void) +{ + gint k; + for (k = 1; k <= lineno_; ++k) update_bp_ (k); + mixgtk_mixal_update (); +} + +/* callbacks */ +static void +mixal_row_clicked_ (GtkTreeIter *iter) +{ + + gint addr = MIX_VM_CELL_NO; + gtk_tree_model_get (GTK_TREE_MODEL (clist_store_), + iter, CLIST_ADDRESS_NO_COL, &addr, -1); + + if (addr < MIX_VM_CELL_NO) + { + gboolean isset = mix_vm_has_breakpoint_at_address (vm_, addr); + if (isset) + mix_vm_clear_breakpoint_address (vm_, addr); + else + mix_vm_set_breakpoint_address (vm_, addr); + update_bp_ (find_address_ (addr)); + } +} + +static void +mixal_motion_ (GtkTreeIter *iter) +{ + static gint last_row = 0; + static guint last_message = 0; + + gint row = last_row; + + gtk_tree_model_get (GTK_TREE_MODEL (clist_store_), iter, + CLIST_LINE_NO_COL, &row, -1); + + if (row > 0 && row != last_row && tips_text_) + { + const gchar *msg = NULL; + last_row = row; + if (last_message) + gtk_statusbar_remove (status_, status_context_, last_message); + msg = (const gchar *)g_ptr_array_index (tips_text_, row - 1); + if (msg) + last_message = gtk_statusbar_push (status_, status_context_, msg); + else + last_message = 0; + } +} + +static gboolean +mixal_event_ (GtkWidget *w, GdkEvent *event, gpointer data) +{ + GdkEventType type = event->type; + if ((type == GDK_BUTTON_PRESS || type == GDK_MOTION_NOTIFY) + && (gtk_tree_view_get_bin_window (clist_) == event->any.window)) + { + gdouble x = (type == GDK_BUTTON_PRESS)? event->button.x : event->motion.x; + gdouble y = (type == GDK_BUTTON_PRESS)? event->button.y : event->motion.y; + GtkTreeIter iter; + GtkTreePath *path = NULL; + GtkTreeViewColumn *col = NULL; + if (gtk_tree_view_get_path_at_pos (clist_, x, y, &path, &col, NULL, NULL) + && gtk_tree_model_get_iter (GTK_TREE_MODEL (clist_store_), + &iter, path)) + { + if (type == GDK_BUTTON_PRESS) mixal_row_clicked_ (&iter); + else mixal_motion_ (&iter); + } + if (path) gtk_tree_path_free (path); + return TRUE; + } + return FALSE; +} + +void +on_symbol_ok_clicked () +{ + gtk_widget_hide (symbols_dlg_); +} + +void +on_symbols_activate () +{ + if (!symbols_dlg_) init_symbols_ (); + gtk_widget_show (symbols_dlg_); +} + +void +on_mixal_leave_notify_event () +{ + if (status_ != NULL) gtk_statusbar_pop (status_, status_context_); +} + +void +on_mixal_font_activate () +{ + GtkWidget *w[] = { GTK_WIDGET (clist_) }; + mixgtk_fontsel_query_font (MIX_FONT_MIXAL, w, 1); +} + +void +on_symbols_font_activate () +{ + if (symbols_view_ != NULL) + { + GtkWidget *w[] = { GTK_WIDGET (symbols_view_) }; + mixgtk_fontsel_query_font (MIX_FONT_SYMBOLS, w, 1); + } + else + mixgtk_fontsel_query_font (MIX_FONT_SYMBOLS, NULL, 0); +} diff --git a/mixgtk/mixgtk_mixal.h b/mixgtk/mixgtk_mixal.h new file mode 100644 index 0000000..1afe9a0 --- /dev/null +++ b/mixgtk/mixgtk_mixal.h @@ -0,0 +1,66 @@ +/* -*-c-*- ---------------- mixgtk_mixal.h : + * Declarations for functions displaying the mixal source file + * ------------------------------------------------------------------ + * $Id: mixgtk_mixal.h,v 1.8 2005/09/20 19:43:14 jao Exp $ + * ------------------------------------------------------------------ + * Copyright (C) 2001, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + + +#ifndef MIXGTK_MIXAL_H +#define MIXGTK_MIXAL_H + +#include +#include +#include "mixgtk_widgets.h" + + +/* initialise the mixal widget */ +extern GtkWidget * +mixgtk_mixal_init (mix_vm_t *vm); + +extern void +mixgtk_mixal_reparent (GtkStatusbar *stat); + +/* load the corresponding mixal file */ +extern void +mixgtk_mixal_load_file (void); + +/* update the widget */ +extern void +mixgtk_mixal_update (void); + +extern void +mixgtk_mixal_update_fonts (void); + +extern void +mixgtk_mixal_pop_status (void); + +/* breakpoints */ +extern void +mixgtk_mixal_update_bp_at_address (guint addr); + +extern void +mixgtk_mixal_update_bp_at_line (guint line); + +extern void +mixgtk_mixal_update_bp_all (void); + + +#endif /* MIXGTK_MIXAL_H */ + diff --git a/mixgtk/mixgtk_mixvm.c b/mixgtk/mixgtk_mixvm.c new file mode 100644 index 0000000..cc74e27 --- /dev/null +++ b/mixgtk/mixgtk_mixvm.c @@ -0,0 +1,529 @@ +/* -*-c-*- -------------- mixgtk_mixvm.c : + * Implementation of the functions declared in mixgtk_mixvm.h + * ------------------------------------------------------------------ + * $Id: mixgtk_mixvm.c,v 1.16 2005/09/20 19:43:14 jao Exp $ + * ------------------------------------------------------------------ + * Copyright (C) 2001, 2002, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include +#include +#include "mixgtk_widgets.h" +#include "mixgtk_fontsel.h" +#include "mixgtk_mixvm.h" +#include "mixgtk_cmd_dispatcher.h" +#include "mixgtk_input.h" + + +/* Local variables */ + +#define REGISTER_NO_ (MIXGTK_WIDGET_rI6 - MIXGTK_WIDGET_rA + 1) + +static GtkEntry *reg_entries_[REGISTER_NO_]; +static GtkTooltips *tips_ = NULL; +static GtkEntry *loc_entry_; +static GtkWidget *goto_ = NULL; +static GtkEntry *goto_entry_ = NULL; +static GtkToggleButton *over_button_; +static GtkToggleButton *cmp_buttons_[3]; +static GtkTreeView *memory_; +static GtkListStore *mem_store_; +static GtkLabel *laptime_; +static GtkLabel *progtime_; +static GtkLabel *uptime_; +static mix_vm_t *vm_; + + +/* Static function prototypes */ +static void init_goto_ (void); +static void update_register_ (mixgtk_widget_id_t reg); +static gboolean init_mem_ (void); + + +enum { + MEM_ADDRESS_COL, + MEM_CONTENTS_COL, + MEM_COL_NO +}; + + +/* initialise the mixvm widgets */ +gboolean +mixgtk_mixvm_init (mix_vm_t *vm) +{ + int k; + + g_assert (vm != NULL); + + vm_ = vm; + + if (!tips_) tips_ = gtk_tooltips_new (); + + for (k = 0; k < REGISTER_NO_; ++k) + { + reg_entries_[k] = + GTK_ENTRY (mixgtk_widget_factory_get(MIXGTK_MIXVM_DIALOG, + MIXGTK_WIDGET_rA + k)); + g_assert (reg_entries_[k] != NULL); + mixgtk_fontsel_set_font (MIX_FONT_MIXVM, + GTK_WIDGET (reg_entries_[k])); + } + + loc_entry_ = + GTK_ENTRY (mixgtk_widget_factory_get (MIXGTK_MIXVM_DIALOG, + MIXGTK_WIDGET_LOC)); + g_assert (loc_entry_ != NULL); + mixgtk_fontsel_set_font (MIX_FONT_MIXVM, GTK_WIDGET (loc_entry_)); + + uptime_ = + GTK_LABEL (mixgtk_widget_factory_get (MIXGTK_MIXVM_DIALOG, + MIXGTK_WIDGET_UPTIME)); + g_assert (uptime_ != NULL); + + progtime_ = + GTK_LABEL (mixgtk_widget_factory_get (MIXGTK_MIXVM_DIALOG, + MIXGTK_WIDGET_PROGTIME)); + g_assert (progtime_ != NULL); + + laptime_ = + GTK_LABEL (mixgtk_widget_factory_get (MIXGTK_MIXVM_DIALOG, + MIXGTK_WIDGET_LAPTIME)); + g_assert (laptime_ != NULL); + + over_button_ = + GTK_TOGGLE_BUTTON + (mixgtk_widget_factory_get (MIXGTK_MIXVM_DIALOG, MIXGTK_WIDGET_OVER)); + g_assert (over_button_ != NULL); + + for (k = 0; k < 3; ++k) + { + cmp_buttons_[k] = GTK_TOGGLE_BUTTON + (mixgtk_widget_factory_get (MIXGTK_MIXVM_DIALOG, + MIXGTK_WIDGET_CMP_L +k)); + g_assert (cmp_buttons_[k] != NULL); + } + init_mem_ (); + + return TRUE; +} + +static GtkWidget ** +text_widgets_ (gint *n) +{ + static GtkWidget *w[REGISTER_NO_ + 2] = { NULL}; + + if (w[0] == NULL) + { + gint k; + w[0] = GTK_WIDGET (loc_entry_); + w[1] = GTK_WIDGET (memory_); + for (k = 0; k < REGISTER_NO_; ++k) + w[k + 2] = GTK_WIDGET (reg_entries_[k]); + }; + + if (n) *n = REGISTER_NO_ + 2; + + return w; +} + +void +mixgtk_mixvm_update_fonts (void) +{ + gint k, n = 0; + GtkWidget **w = text_widgets_ (&n); + for (k = 0; k < n; ++k) + mixgtk_fontsel_set_font (MIX_FONT_MIXVM, w[k]); +} + +/* update register widgets */ +void +mixgtk_mixvm_update_registers (void) +{ + gint k; + for (k = MIXGTK_WIDGET_rA; k <= MIXGTK_WIDGET_rI6; ++k) + update_register_ (k); +} + +/* update the overflow toggle */ +void +mixgtk_mixvm_update_over_toggle (void) +{ + g_assert (over_button_); + gtk_toggle_button_set_active (over_button_, + mix_vm_get_overflow (vm_)); +} + +/* update the comparison flag */ +void +mixgtk_mixvm_update_cmp (void) +{ + gint toggle; + + g_assert (cmp_buttons_); + + toggle = mix_vm_get_cmpflag (vm_); + gtk_toggle_button_set_active (cmp_buttons_[toggle], TRUE); +} + + +/* update the memory cells */ +void +mixgtk_mixvm_update_cells (void) +{ + static gchar BUFFER[20]; + GtkTreeIter iter; + gboolean valid = + gtk_tree_model_get_iter_first (GTK_TREE_MODEL (mem_store_), &iter); + gint k = 0; + + while (valid) + { + mix_word_print_to_buffer (mix_vm_get_addr_contents (vm_, k++), BUFFER); + gtk_list_store_set (mem_store_, &iter, MEM_CONTENTS_COL, BUFFER, -1); + valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (mem_store_), &iter); + } +} + +void +mixgtk_mixvm_update_cells_to_address (gint address) +{ + GtkTreePath *path = gtk_tree_path_new_from_indices (address, -1); + + if (address >= MIX_VM_CELL_NO) return; + gtk_tree_view_scroll_to_cell (memory_, path, NULL, TRUE, 0, 0); + gtk_tree_path_free (path); +} + +/* update the loc pointer */ +void +mixgtk_mixvm_update_loc (void) +{ + enum {SIZE = 10 }; + static gchar BUFFER[SIZE]; + mix_short_t locval; + + g_assert (loc_entry_); + + locval = mix_vm_get_prog_count (vm_); + g_snprintf (BUFFER, SIZE, "%04d", mix_short_magnitude (locval)); + gtk_entry_set_text (loc_entry_, BUFFER); +} + +/* update times */ +void +mixgtk_mixvm_update_times (void) +{ + enum {SIZE = 20 }; + static gchar BUFFER[SIZE]; + gint uptime, progtime, laptime; + + g_assert (uptime_ && progtime_ && laptime_); + mixgtk_cmd_dispatcher_get_times (&uptime, &progtime, &laptime); + g_snprintf (BUFFER, SIZE, "%d", uptime); + gtk_label_set_text (uptime_, BUFFER); + g_snprintf (BUFFER, SIZE, "%d", progtime); + gtk_label_set_text (progtime_, BUFFER); + g_snprintf (BUFFER, SIZE, "%d", laptime); + gtk_label_set_text (laptime_, BUFFER); +} + + +/* update all mixvm widgets */ +void +mixgtk_mixvm_update_vm_widgets (void) +{ + mixgtk_mixvm_update_registers (); + mixgtk_mixvm_update_loc (); + mixgtk_mixvm_update_over_toggle (); + mixgtk_mixvm_update_cmp (); + mixgtk_mixvm_update_cells (); + mixgtk_mixvm_update_times (); +} + + +/* update cmp flag */ +void +on_cmp_e_toggled (GtkWidget *widget, gpointer data) +{ + if (GTK_TOGGLE_BUTTON (widget)->active) + mix_vm_set_cmpflag (vm_, mix_EQ); +} + +void +on_cmp_l_toggled (GtkWidget *widget, gpointer data) +{ + if (GTK_TOGGLE_BUTTON (widget)->active) + mix_vm_set_cmpflag (vm_, mix_LESS); +} + +void +on_cmp_g_toggled (GtkWidget *widget, gpointer data) +{ + if (GTK_TOGGLE_BUTTON (widget)->active) + mix_vm_set_cmpflag (vm_, mix_GREAT); +} + +void +on_overflow_toggled (GtkWidget *widget, gpointer data) +{ + mix_vm_set_overflow (vm_, GTK_TOGGLE_BUTTON (widget)->active); +} + +void +on_loc_arrow_clicked (GtkWidget *widget, gpointer data) +{ + gint address = mix_short_magnitude (mix_vm_get_prog_count (vm_)); + mixgtk_mixvm_update_cells_to_address (address); +} + +static void +register_AX_ (mix_word_t w, gpointer reg) +{ + gint k = GPOINTER_TO_INT (reg); + if (k == 0) + mix_vm_set_rA (vm_, w); + else + mix_vm_set_rX (vm_, w); + update_register_ (MIXGTK_WIDGET_rA + k); +} + +static void +register_j_ (mix_word_t w, gpointer data) +{ + if (mix_word_is_negative (w)) mix_word_reverse_sign (w); + mix_vm_set_rJ (vm_, mix_word_to_short_fast (w)); + update_register_ (MIXGTK_WIDGET_rJ); +} + +static void +register_i_ (mix_word_t w, gpointer reg) +{ + mix_vm_set_rI (vm_, GPOINTER_TO_INT (reg), mix_word_to_short_fast (w)); + update_register_ (MIXGTK_WIDGET_rI1 - 1 + GPOINTER_TO_INT (reg)); +} + +gboolean +on_register_click (GtkWidget *w, GdkEvent *e, gpointer data) +{ + enum {SIZE = 20}; + static gchar BUFFER[SIZE]; + gint k; + + if (w == GTK_WIDGET (reg_entries_[0])) + mixgtk_input_word (_("Register A"), mix_vm_get_rA (vm_), + register_AX_, GINT_TO_POINTER (0)); + else if (w == GTK_WIDGET (reg_entries_[1])) + mixgtk_input_word (_("Register X"), mix_vm_get_rX (vm_), + register_AX_, GINT_TO_POINTER(1)); + else if (w == GTK_WIDGET (reg_entries_[2])) + mixgtk_input_short (_("Register J"), mix_vm_get_rJ (vm_), + register_j_, NULL); + else for (k = 1; k < 7; ++k) + { + if (w == GTK_WIDGET (reg_entries_[2 + k])) + { + g_snprintf (BUFFER, SIZE, _("Register I%d"), k); + mixgtk_input_short (BUFFER, mix_vm_get_rI (vm_, k), + register_i_, GINT_TO_POINTER (k)); + break; + } + } + return TRUE; +} + +static void +mem_cell_ (mix_word_t w, gpointer a) +{ + mix_short_t addr = mix_short_new (GPOINTER_TO_INT (a)); + mix_vm_set_addr_contents (vm_, addr, w); + mixgtk_mixvm_update_cells (); +} + +void +on_mix_font_activate (void) +{ + gint n; + GtkWidget **w = text_widgets_ (&n); + mixgtk_fontsel_query_font (MIX_FONT_MIXVM, w, n); +} + + + +/* static functions */ +static void +init_goto_ (void) +{ + goto_ = mixgtk_widget_factory_get_dialog (MIXGTK_GOTO_DIALOG); + g_assert (goto_ != NULL); + goto_entry_ = + GTK_ENTRY (mixgtk_widget_factory_get (MIXGTK_GOTO_DIALOG, + MIXGTK_WIDGET_GOTO_ENTRY)); + g_assert (goto_entry_ != NULL); +} + +static void +update_register_ (mixgtk_widget_id_t reg) +{ + static gchar BUFFER[20]; + mix_word_t tipval = MIX_WORD_ZERO; + switch (reg) + { + case MIXGTK_WIDGET_rA: + tipval = mix_vm_get_rA (vm_); + mix_word_print_to_buffer (tipval, BUFFER); + break; + case MIXGTK_WIDGET_rX: + tipval = mix_vm_get_rX (vm_); + mix_word_print_to_buffer (tipval, BUFFER); + break; + case MIXGTK_WIDGET_rJ: + tipval = mix_short_to_word_fast (mix_vm_get_rJ (vm_)); + mix_short_print_to_buffer (mix_vm_get_rJ (vm_), BUFFER); + break; + case MIXGTK_WIDGET_rI1: + case MIXGTK_WIDGET_rI2: + case MIXGTK_WIDGET_rI3: + case MIXGTK_WIDGET_rI4: + case MIXGTK_WIDGET_rI5: + case MIXGTK_WIDGET_rI6: + { + gint k = reg - MIXGTK_WIDGET_rI1 + 1; + tipval = mix_short_to_word_fast (mix_vm_get_rI (vm_, k)); + mix_short_print_to_buffer (mix_vm_get_rI (vm_, k), BUFFER); + } + break; + default: + g_assert_not_reached (); + } + gtk_entry_set_text (reg_entries_[reg - MIXGTK_WIDGET_rA], BUFFER); + g_snprintf (BUFFER, 20, "%s%ld", mix_word_is_negative (tipval)? "-" : "", + mix_word_magnitude (tipval)); + gtk_tooltips_set_tip (tips_, + GTK_WIDGET (reg_entries_[reg - MIXGTK_WIDGET_rA]), + BUFFER, NULL); + +} + + +static void +cells_clicked_ (GtkTreeViewColumn* col, gpointer data) +{ + if (!goto_) init_goto_ (); + if (gtk_dialog_run (GTK_DIALOG (goto_)) == GTK_RESPONSE_OK) + { + const gchar *txt = gtk_entry_get_text (goto_entry_); + mix_short_t addr = mix_short_new (atoi (txt)); + if (addr < MIX_VM_CELL_NO) + mixgtk_mixvm_update_cells_to_address (addr); + } + gtk_widget_hide (goto_); +} + +static gboolean +cont_clicked_ (GtkWidget *w, GdkEvent *event, gpointer data) +{ + enum {SIZE = 30}; + static gchar BUFFER[SIZE]; + + if (event->type == GDK_BUTTON_PRESS) + { + GtkTreeIter iter; + GtkTreeModel *model; + GtkTreeSelection *selection; + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (memory_)); + + if (gtk_tree_selection_get_selected (selection, &model, &iter)) + { + gint addr; + + gtk_tree_model_get (model, &iter, MEM_ADDRESS_COL, &addr, -1); + g_snprintf (BUFFER, SIZE, _("Memory cell no. %d"), addr); + mixgtk_input_word + (BUFFER, + mix_vm_get_addr_contents (vm_, mix_short_new (addr)), + mem_cell_, GINT_TO_POINTER (addr)); + } + } + + return FALSE; +} + + +static gboolean +init_mem_ (void) +{ + gint k; + GtkTreeIter iter; + GtkCellRenderer *renderer; + GtkTreeViewColumn *col; + + /* model */ + + mem_store_ = gtk_list_store_new (MEM_COL_NO, G_TYPE_INT, G_TYPE_STRING); + + g_assert (mem_store_); + + for (k = 0; k< MIX_VM_CELL_NO; ++k) + { + gtk_list_store_append (mem_store_, &iter); + gtk_list_store_set (mem_store_, &iter, + MEM_ADDRESS_COL, k, + MEM_CONTENTS_COL, "+ 00 00 00 00 00", + -1); + } + + /* view */ + + renderer = gtk_cell_renderer_text_new (); + memory_ = + GTK_TREE_VIEW (mixgtk_widget_factory_get (MIXGTK_MIXVM_DIALOG, + MIXGTK_WIDGET_CELLS)); + + g_assert (memory_); + g_assert (renderer); + + gtk_tree_view_set_model (memory_, GTK_TREE_MODEL (mem_store_)); + gtk_tree_view_set_headers_clickable (memory_, TRUE); + g_object_unref (G_OBJECT (mem_store_)); + + col = gtk_tree_view_column_new_with_attributes ("Address", renderer, + "text", 0, NULL); + gtk_tree_view_column_set_clickable (col, TRUE); + g_signal_connect (G_OBJECT (col), "clicked", + G_CALLBACK (cells_clicked_), NULL); + + gtk_tree_view_append_column (memory_, col); + + + col = gtk_tree_view_column_new_with_attributes ("Contents", renderer, + "text", 1, NULL); + gtk_tree_view_column_set_clickable (col, TRUE); + g_signal_connect (G_OBJECT (col), "clicked", + G_CALLBACK (cont_clicked_), NULL); + + gtk_tree_view_append_column (memory_, col); + + g_signal_connect (G_OBJECT (memory_), "event-after", + G_CALLBACK (cont_clicked_), NULL); + + mixgtk_fontsel_set_font (MIX_FONT_MIXVM, GTK_WIDGET (memory_)); + + return TRUE; +} + diff --git a/mixgtk/mixgtk_mixvm.h b/mixgtk/mixgtk_mixvm.h new file mode 100644 index 0000000..79a8d72 --- /dev/null +++ b/mixgtk/mixgtk_mixvm.h @@ -0,0 +1,72 @@ +/* -*-c-*- ---------------- mixgtk_mixvm.h : + * Functions dealing with the mixvm widgets + * ------------------------------------------------------------------ + * $Id: mixgtk_mixvm.h,v 1.6 2005/09/20 19:43:14 jao Exp $ + * ------------------------------------------------------------------ + * Copyright (C) 2001, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + + +#ifndef MIXGTK_MIXVM_H +#define MIXGTK_MIXVM_H + +#include +#include "mixgtk.h" +#include "mixgtk_widgets.h" + +/* initialise the mixvm widgets */ +extern gboolean +mixgtk_mixvm_init (mix_vm_t *vm); + +extern void +mixgtk_mixvm_update_fonts (void); + +/* update register widgets */ +extern void +mixgtk_mixvm_update_registers (void); + +/* update the overflow toggle */ +extern void +mixgtk_mixvm_update_over_toggle (void); + +/* update the comparison flag */ +extern void +mixgtk_mixvm_update_cmp (void); + +/* update the memory cells */ +extern void +mixgtk_mixvm_update_cells (void); + +extern void +mixgtk_mixvm_update_cells_to_address (gint address); + +/* update the loc pointer */ +extern void +mixgtk_mixvm_update_loc (void); + +/* update times */ +extern void +mixgtk_mixvm_update_times (void); + +/* update all mixvm widgets */ +extern void +mixgtk_mixvm_update_vm_widgets (void); + + +#endif /* MIXGTK_MIXVM_H */ + diff --git a/mixgtk/mixgtk_widgets.c b/mixgtk/mixgtk_widgets.c new file mode 100644 index 0000000..724b578 --- /dev/null +++ b/mixgtk/mixgtk_widgets.c @@ -0,0 +1,153 @@ +/* -*-c-*- -------------- mixgtk_widgets.c : + * Implementation of the functions declared in mixgtk_widgets.h + * ------------------------------------------------------------------ + * Last change: Time-stamp: "2001-04-29 14:32:17 jao" + * ------------------------------------------------------------------ + * Copyright (C) 2001, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + + +#include +#include +#include +#include "mixgtk_config.h" +#include "mixgtk_widgets.h" + +/* dialog names */ +static const gchar * dnames_[] = { + "main_window", + "mixvm_window", + "mixal_window", + "devices_window", + "word_dialog", + "about_dialog", + "goto_dialog", + "fontsel_dialog", + "devform_dialog", + "external_dialog", + "symbols_dialog", + "input_dialog", + "devdir_dialog" +}; + +#define DLG_NO_ (sizeof (dnames_) / sizeof(dnames_[0])) + +/* widget names */ +static const gchar *names_[] = { + "main_statusbar", + "attach_button", + "main_notebook", + "mixvm_widget", + "mixvm_container", + "command_prompt", + "command_log", + "dev_container", + "mixal_container", + "mixal_statusbar", + "rA_entry", + "rX_entry", + "rJ_entry", + "rI1_entry", + "rI2_entry", + "rI3_entry", + "rI4_entry", + "rI5_entry", + "rI6_entry", + "lesser_radio", + "equal_radio", + "greater_radio", + "over_toggle", + "memory_cells", + "elapsed_label", + "program_label", + "uptime_label", + "devices_container", + "loc_entry", + "goto_entry", + NULL +}; + +#define WIDGET_NO_ (sizeof (names_) / sizeof (names_[0])) + +/* the glade specs */ +static GladeXML *xml_[DLG_NO_] = {NULL}; + +/* the xml file name */ +static const gchar *file_ = NULL; + +static void init_xml_ (mixgtk_dialog_id_t dlg) +{ + xml_[dlg] = glade_xml_new (file_, dnames_[dlg], NULL); + glade_xml_signal_autoconnect (xml_[dlg]); + g_assert (xml_[dlg] != NULL); +} + +/* create a new factory from an xml glade file */ +gboolean +mixgtk_widget_factory_init (void) +{ + if (!file_) + { + const gchar *glade_file = GLADE_FILE; + glade_init (); + if (access (glade_file, R_OK)) { + if (access (LOCAL_GLADE_FILE, R_OK)) return FALSE; + glade_file = LOCAL_GLADE_FILE; + } + file_ = g_strdup (glade_file); + } + else + { + gint k; + for (k = 0; k < DLG_NO_; ++k) if (xml_[k]) xml_[k] = NULL; + } + + init_xml_ (MIXGTK_MAIN); + return TRUE; +} + +/* get a widget */ +GtkWidget * +mixgtk_widget_factory_get (mixgtk_dialog_id_t dlg, mixgtk_widget_id_t widget) +{ + g_assert (widget < WIDGET_NO_); + + return mixgtk_widget_factory_get_child_by_name (dlg, names_[widget]); +} + + +GtkWidget * +mixgtk_widget_factory_get_dialog (mixgtk_dialog_id_t dlg) +{ + g_assert (dlg < DLG_NO_); + + if (!xml_[dlg]) init_xml_ (dlg); + return glade_xml_get_widget (xml_[dlg], dnames_[dlg]); +} + +GtkWidget * +mixgtk_widget_factory_get_child_by_name (mixgtk_dialog_id_t dlg, + const gchar *name) +{ + g_assert (dlg < DLG_NO_); + g_assert (name != NULL); + if (!xml_[dlg]) init_xml_ (dlg); + return glade_xml_get_widget (xml_[dlg], name); +} + + diff --git a/mixgtk/mixgtk_widgets.h b/mixgtk/mixgtk_widgets.h new file mode 100644 index 0000000..720f962 --- /dev/null +++ b/mixgtk/mixgtk_widgets.h @@ -0,0 +1,102 @@ +/* -*-c-*- ---------------- mixgtk_widgets.h : + * glade-based factory of mixvm widgets + * ------------------------------------------------------------------ + * $Id: mixgtk_widgets.h,v 1.15 2005/09/20 19:43:14 jao Exp $ + * ------------------------------------------------------------------ + * Copyright (C) 2001, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + + +#ifndef MIXGTK_WIDGETS_H +#define MIXGTK_WIDGETS_H + +#include +#include + +/* enumeration of gmixvm dialogs */ +typedef enum { + MIXGTK_MAIN, /* main app window */ + MIXGTK_MIXVM_DIALOG, /* mixvm dialog */ + MIXGTK_MIXAL_DIALOG, /* mixal dialog */ + MIXGTK_DEVICES_DIALOG, /* devices dialog */ + MIXGTK_WORD_DIALOG, /* input dialog for a mix word */ + MIXGTK_ABOUT_DIALOG, + MIXGTK_GOTO_DIALOG, + MIXGTK_FONTSEL_DIALOG, /* font selection dialog */ + MIXGTK_DEVFORM_DIALOG, /* device format config dialog */ + MIXGTK_EXTERNPROG_DIALOG, /* external programs dialog */ + MIXGTK_SYMBOLS_DIALOG, /* symbol table dialog */ + MIXGTK_INPUT_DIALOG, /* console input dialog */ + MIXGTK_DEVDIR_DIALOG /* devices directory chooser */ +} mixgtk_dialog_id_t; + +/* enumeration of mixvm widget ids */ +typedef enum { + MIXGTK_WIDGET_STATUSBAR, + MIXGTK_WIDGET_ATTACH_BUTTON, + MIXGTK_WIDGET_NOTEBOOK, /* the notebook */ + MIXGTK_WIDGET_MIXVM, /* virtual machine */ + MIXGTK_WIDGET_MIXVM_CONTAINER, + MIXGTK_WIDGET_PROMPT, /* command prompt */ + MIXGTK_WIDGET_LOG, /* command output */ + MIXGTK_WIDGET_DEV_CONTAINER, + MIXGTK_WIDGET_MIXAL_CONTAINER, + MIXGTK_WIDGET_MIXAL_STATUSBAR, + 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_DEVICES, + MIXGTK_WIDGET_LOC, + MIXGTK_WIDGET_GOTO_ENTRY, + MIXGTK_WIDGET_NONE +} mixgtk_widget_id_t; + + +/* create a new factory from an xml glade file */ +extern gboolean +mixgtk_widget_factory_init (void); + +/* get a dialog */ +extern GtkWidget * +mixgtk_widget_factory_get_dialog (mixgtk_dialog_id_t dlg); + +/* get a widget */ +extern GtkWidget * +mixgtk_widget_factory_get (mixgtk_dialog_id_t dlg, mixgtk_widget_id_t widget); + +/* Get a widget by name */ +extern GtkWidget * +mixgtk_widget_factory_get_child_by_name (mixgtk_dialog_id_t dlg, + const gchar *name); + +#endif /* MIXGTK_WIDGETS_H */ + diff --git a/mixgtk/mixgtk_wm.c b/mixgtk/mixgtk_wm.c new file mode 100644 index 0000000..7821d0e --- /dev/null +++ b/mixgtk/mixgtk_wm.c @@ -0,0 +1,573 @@ +/* -*-c-*- -------------- mixgtk_wm.c : + * Implementation of the functions declared in mixgtk_wm.h + * ------------------------------------------------------------------ + * $Id: mixgtk_wm.c,v 1.12 2005/09/20 19:43:14 jao Exp $ + * ------------------------------------------------------------------ + * Copyright (C) 2001, 2002, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include + +#include "mixgtk_wm.h" + +#include "mixgtk_widgets.h" +#include "mixgtk_config.h" +#include "mixgtk_device.h" +#include "mixgtk_mixvm.h" +#include "mixgtk_mixal.h" +#include "mixgtk_widgets.h" +#include "mixgtk_cmd_dispatcher.h" +#include "mixgtk.h" + + +typedef struct window_info_t_ +{ + mixgtk_dialog_id_t dialog; + GtkWidget *widget; + GtkCheckMenuItem *menu; + const gchar *menu_name; + const gchar *config_key; + gboolean detached; + void (*detach) (void); + void (*attach) (void); +} window_info_t_; + +static const gchar *DETACH_YES_ = "Yes"; +static const gchar *DETACH_NO_ = "No"; +static GtkWidget *about_ = NULL; + +static GtkContainer *mixvm_container_ = NULL; +static GtkContainer *mixal_container_ = NULL; +static GtkContainer *dev_container_ = NULL; + +static const gchar *TB_MENU_NAME_ = "show_toolbars"; +static GtkCheckMenuItem *tb_menu_ = NULL; +static GtkNotebook *notebook_ = NULL; + +static mix_vm_t *vm_ = NULL; + +static void init_info_ (void); +static void init_notebook_ (void); +static void init_dispatcher_ (void); +static void init_mixvm_ (void); +static void init_mixal_ (void); +static void init_dev_ (void); +static void init_signals_ (void); +static void init_visibility_ (void); +static void init_tb_ (void); +static void init_about_ (void); +static void init_autosave_ (void); +static void show_toolbars_ (gboolean show); +static void add_page_ (GtkWidget *w, mixgtk_window_id_t id); +static void mixvm_attach_ (void); +static void mixvm_detach_ (void); +static void mixal_attach_ (void); +static void mixal_detach_ (void); +static void dev_attach_ (void); +static void dev_detach_ (void); +static void on_nb_switch_ (GtkNotebook *notebook, GtkWidget *page, + guint page_num, gpointer user_data); + +static window_info_t_ infos_[] = { + {MIXGTK_MIXVM_DIALOG, NULL, NULL, "detach_vm", "MIX.detach", + FALSE, mixvm_detach_, mixvm_attach_}, + {MIXGTK_MIXAL_DIALOG, NULL, NULL, "detach_source", "MIXAL.detach", + FALSE, mixal_detach_, mixal_attach_}, + {MIXGTK_DEVICES_DIALOG, NULL, NULL, "detach_dev", "Devices.detach", + FALSE, dev_detach_, dev_attach_} +}; + +static size_t INF_NO_ = sizeof (infos_) / sizeof (infos_[0]); + + +gboolean +mixgtk_wm_init (void) +{ + gint k; + + init_info_ (); + init_notebook_ (); + init_dispatcher_ (); + init_mixvm_ (); + init_mixal_ (); + init_dev_ (); + + for (k = 0; k < INF_NO_; ++k) + { + if (infos_[k].detached) + mixgtk_wm_detach_window (k); + else + mixgtk_wm_attach_window (k); + } + + init_tb_ (); + init_about_ (); + init_autosave_ (); + init_visibility_ (); + init_signals_ (); + + return TRUE; +} + +void +mixgtk_wm_detach_window (mixgtk_window_id_t w) +{ + if (w < INF_NO_) + { + (*(infos_[w].detach)) (); + infos_[w].detached = TRUE; + gtk_check_menu_item_set_active (infos_[w].menu, TRUE); + mixgtk_config_update (infos_[w].config_key, DETACH_YES_); + if (infos_[w].widget != NULL) gtk_widget_show (infos_[w].widget); + if (gtk_notebook_get_n_pages (notebook_) < 1) + gtk_widget_hide (GTK_WIDGET (notebook_)); + gtk_widget_show (mixgtk_widget_factory_get_dialog (infos_[w].dialog)); + } +} + +void +mixgtk_wm_attach_window (mixgtk_window_id_t w) +{ + if (w < INF_NO_) + { + gint page = gtk_notebook_page_num (notebook_, infos_[w].widget); + + gtk_widget_hide (mixgtk_widget_factory_get_dialog (infos_[w].dialog)); + + if (page < 0) (*(infos_[w].attach)) (); + + infos_[w].detached = FALSE; + gtk_check_menu_item_set_active (infos_[w].menu, FALSE); + mixgtk_config_update (infos_[w].config_key, DETACH_NO_); + if (gtk_notebook_get_n_pages (notebook_) == 1) + gtk_widget_show (GTK_WIDGET (notebook_)); + } +} + + + +/* callbacks */ +void +on_detach_clicked (GtkWidget *ignored) +{ + gint page = gtk_notebook_get_current_page (notebook_); + if (page >= 0) + { + gint k; + GtkWidget *w = gtk_notebook_get_nth_page (notebook_, page); + + for (k = 0; k < INF_NO_; ++k) + if (infos_[k].widget == w) mixgtk_wm_detach_window (k); + } +} + +void +on_attach_all_clicked () +{ + gint k; + for (k = INF_NO_; k > 0; --k) + if (infos_[k - 1].detached) mixgtk_wm_attach_window (k - 1); +} + +void +on_attach_toggled (GtkCheckMenuItem *item) +{ + gint k; + for (k = 0; k < INF_NO_; ++k) + if (item == infos_[k].menu) break; + g_return_if_fail (k < INF_NO_); + if (item->active) mixgtk_wm_detach_window (k); + else mixgtk_wm_attach_window (k); + mixgtk_config_update (infos_[k].config_key, + (item->active)? DETACH_YES_ : DETACH_NO_); +} + +void +on_window_hide (GtkWidget *w) +{ + gint k; + for (k = 0; k < INF_NO_; ++k) + if (w == mixgtk_widget_factory_get_dialog (infos_[k].dialog)) break; + g_return_if_fail (k < INF_NO_); + mixgtk_wm_attach_window (k); +} + +void +on_show_toolbars_toggled (GtkCheckMenuItem *item) +{ + if (item->active != mixgtk_config_show_toolbars ()) + show_toolbars_ (item->active); +} + +void +on_widget_attach (GtkWidget *ign, gpointer id) +{ + mixgtk_wm_attach_window (GPOINTER_TO_INT (id)); +} + + +/* about box */ +void +on_about_activate (GtkWidget *w, gpointer data) +{ + if (!about_) init_about_ (); + gtk_widget_show (about_); +} + + +static void +init_info_ (void) +{ + gint k; + for (k = 0; k < INF_NO_; ++k) + { + const gchar *txt; + + infos_[k].menu = + GTK_CHECK_MENU_ITEM + (mixgtk_widget_factory_get_child_by_name (MIXGTK_MAIN, + infos_[k].menu_name)); + g_assert (infos_[k].menu != NULL); + txt = mixgtk_config_get (infos_[k].config_key); + infos_[k].detached = txt && !g_ascii_strcasecmp (txt, DETACH_YES_); + } +} + +static void +init_notebook_ (void) +{ + notebook_ = + GTK_NOTEBOOK (mixgtk_widget_factory_get (MIXGTK_MAIN, + MIXGTK_WIDGET_NOTEBOOK)); + g_assert (notebook_ != NULL); + gtk_widget_show (GTK_WIDGET (notebook_)); +} + +static void +add_page_ (GtkWidget *page, mixgtk_window_id_t id) +{ + static const gchar *LABELS[] = { + N_("_Virtual machine"), N_("_Source"), N_("_Devices") + }; + + gint p = 0; + + g_assert (page != NULL); + g_assert (id < INF_NO_); + g_assert (notebook_ != NULL); + + if (id > MIXGTK_MIXVM_WINDOW) + { + if (id == MIXGTK_DEVICES_WINDOW) + p = gtk_notebook_get_n_pages (notebook_); + else + p = infos_[MIXGTK_MIXVM_WINDOW].detached ? 0 : 1; + } + + gtk_notebook_insert_page (notebook_, page, + gtk_label_new_with_mnemonic (LABELS[id]), + p); + gtk_notebook_set_current_page (notebook_, p); + gtk_widget_show (page); + gtk_widget_show (GTK_WIDGET (notebook_)); +} + +static void +init_signals_ (void) +{ + gint k; + for (k = 0; k < INF_NO_; ++k) + { + GObject *dialog = + G_OBJECT (mixgtk_widget_factory_get_dialog (infos_[k].dialog)); + + GObject *button = + G_OBJECT (mixgtk_widget_factory_get (infos_[k].dialog, + MIXGTK_WIDGET_ATTACH_BUTTON)); + + g_assert (dialog != NULL); + g_assert (button != NULL); + + g_signal_connect (button, "clicked", + G_CALLBACK (on_widget_attach), GINT_TO_POINTER (k)); + g_signal_connect (dialog, "destroy", + G_CALLBACK (on_window_hide), NULL); + g_signal_connect (dialog, "destroy_event", + G_CALLBACK (on_window_hide), NULL); + g_signal_connect (dialog, "delete_event", + G_CALLBACK (on_window_hide), NULL); + g_signal_connect (G_OBJECT (infos_[k].menu), "toggled", + G_CALLBACK (on_attach_toggled), NULL); + } + +} + +static void +init_visibility_ (void) +{ + gint k; + for (k = 0; k < INF_NO_; ++k) + if (infos_[k].detached) + gtk_widget_show (mixgtk_widget_factory_get_dialog (infos_[k].dialog)); + + if (gtk_notebook_get_n_pages (notebook_) > 0) + gtk_notebook_set_current_page (notebook_, 0); + + gtk_widget_show (mixgtk_widget_factory_get_dialog (MIXGTK_MAIN)); +} + +static void +init_dispatcher_ (void) +{ + if (!mixgtk_cmd_dispatcher_init (MIXGTK_MAIN)) + g_assert (FALSE); + vm_ = mixgtk_cmd_dispatcher_get_vm (); + g_assert (vm_ != NULL); +} + +static void +init_mixvm_ (void) +{ + GtkContainer *vm = + GTK_CONTAINER + (mixgtk_widget_factory_get (MIXGTK_MIXVM_DIALOG, MIXGTK_WIDGET_MIXVM)); + + mixvm_container_ = + GTK_CONTAINER (mixgtk_widget_factory_get (MIXGTK_MIXVM_DIALOG, + MIXGTK_WIDGET_MIXVM_CONTAINER)); + + g_assert (mixvm_container_ != NULL); + + g_assert (vm != NULL); + g_object_ref (G_OBJECT (vm)); + infos_[MIXGTK_MIXVM_WINDOW].widget = GTK_WIDGET (vm); + + mixgtk_mixvm_init (vm_); + mixgtk_mixvm_update_vm_widgets (); + + gtk_widget_show (GTK_WIDGET (vm)); + +} + +static void +init_mixal_ (void) +{ + GtkWidget *page = gtk_scrolled_window_new (NULL, NULL); + GtkWidget *mixal = mixgtk_mixal_init (vm_); + + g_assert (page != NULL); + g_assert (mixal != NULL); + + g_object_ref (page); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (page), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + + gtk_container_add (GTK_CONTAINER (page), mixal); + + infos_[MIXGTK_MIXAL_WINDOW].widget = page; + + mixal_container_ = + GTK_CONTAINER (mixgtk_widget_factory_get (MIXGTK_MIXAL_DIALOG, + MIXGTK_WIDGET_MIXAL_CONTAINER)); + + g_assert (mixal_container_ != NULL); + + gtk_container_add (mixal_container_, page); + + gtk_widget_show (mixal); + gtk_widget_show (page); + gtk_widget_show (GTK_WIDGET (mixal_container_)); +} + +static void +init_dev_ (void) +{ + GtkWidget *page = gtk_scrolled_window_new (NULL, NULL); + GtkWidget *devs = mixgtk_device_init (vm_); + + g_assert (page != NULL); + g_assert (devs != NULL); + + g_object_ref (page); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (page), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (page), devs); + + infos_[MIXGTK_DEVICES_WINDOW].widget = page; + + dev_container_ = + GTK_CONTAINER (mixgtk_widget_factory_get (MIXGTK_DEVICES_DIALOG, + MIXGTK_WIDGET_DEV_CONTAINER)); + + g_assert (dev_container_ != NULL); + + gtk_container_add (dev_container_, page); + + gtk_widget_show (devs); + gtk_widget_show (page); +} + +static void +init_tb_ (void) +{ + tb_menu_ = GTK_CHECK_MENU_ITEM + (mixgtk_widget_factory_get_child_by_name (MIXGTK_MAIN, + TB_MENU_NAME_)); + g_assert (tb_menu_ != NULL); + + gtk_check_menu_item_set_active (tb_menu_, mixgtk_config_show_toolbars ()); + show_toolbars_ (mixgtk_config_show_toolbars ()); + + g_signal_connect (G_OBJECT (tb_menu_), "toggled", + G_CALLBACK (on_show_toolbars_toggled), NULL); +} + +static void +show_toolbars_ (gboolean show) +{ + static const gchar *HANDLE_NAME = "tb_handle"; + + int k; + + GtkWidget *handle = + mixgtk_widget_factory_get_child_by_name (MIXGTK_MAIN, HANDLE_NAME); + + if (show) + gtk_widget_show (handle); + else + gtk_widget_hide (handle); + + for (k = 0; k < INF_NO_; ++k) + { + GtkWidget *hd = + mixgtk_widget_factory_get_child_by_name (infos_[k].dialog, HANDLE_NAME); + if (show) gtk_widget_show (hd); else gtk_widget_hide (hd); + } + + mixgtk_config_set_show_toolbars (show); +} + +static void +init_autosave_ (void) +{ +#define AUTOSAVE_ITEM_ "save_on_exit" + + GtkCheckMenuItem *item = GTK_CHECK_MENU_ITEM + (mixgtk_widget_factory_get_child_by_name (MIXGTK_MAIN, AUTOSAVE_ITEM_)); + if (item) + { + gtk_check_menu_item_set_active (item, mixgtk_config_is_autosave ()); + } +} + +static void +init_about_ (void) +{ +#define VERSION_LABEL_ "version_label" +#define GPL_TEXT_ "gpl_text" + GtkWidget *label; + about_ = mixgtk_widget_factory_get_dialog (MIXGTK_ABOUT_DIALOG); + g_assert (about_ != NULL); + label = mixgtk_widget_factory_get_child_by_name (MIXGTK_ABOUT_DIALOG, + VERSION_LABEL_); + g_assert (label != NULL); + gtk_label_set_text (GTK_LABEL (label), VERSION); + gtk_widget_show (label); +} + +static void +mixvm_attach_ (void) +{ + gtk_container_remove (mixvm_container_, infos_[MIXGTK_MIXVM_WINDOW].widget); + add_page_ (infos_[MIXGTK_MIXVM_WINDOW].widget, MIXGTK_MIXVM_WINDOW); +} + +static void +mixvm_detach_ (void) +{ + gtk_widget_reparent (infos_[MIXGTK_MIXVM_WINDOW].widget, + GTK_WIDGET (mixvm_container_)); +} + +static void +mixal_attach_ (void) +{ + static GtkStatusbar *stat = NULL; + + if (stat == NULL) + { + stat = + GTK_STATUSBAR + (mixgtk_widget_factory_get (MIXGTK_MAIN, MIXGTK_WIDGET_STATUSBAR)); + g_assert (stat); + + g_signal_connect (G_OBJECT (notebook_), "switch-page", + G_CALLBACK (on_nb_switch_), NULL); + } + + mixgtk_mixal_reparent (stat); + gtk_container_remove (mixal_container_, infos_[MIXGTK_MIXAL_WINDOW].widget); + add_page_ (infos_[MIXGTK_MIXAL_WINDOW].widget, MIXGTK_MIXAL_WINDOW); +} + +static void +mixal_detach_ (void) +{ + static GtkStatusbar *stat = NULL; + + if (stat == NULL) + { + stat = + GTK_STATUSBAR + (mixgtk_widget_factory_get (MIXGTK_MIXAL_DIALOG, + MIXGTK_WIDGET_MIXAL_STATUSBAR)); + g_assert (stat); + } + + mixgtk_mixal_reparent (stat); + gtk_widget_reparent (infos_[MIXGTK_MIXAL_WINDOW].widget, + GTK_WIDGET (mixal_container_)); +} + +static void +dev_attach_ (void) +{ + gtk_container_remove (dev_container_, infos_[MIXGTK_DEVICES_WINDOW].widget); + add_page_ (infos_[MIXGTK_DEVICES_WINDOW].widget, MIXGTK_DEVICES_WINDOW); +} + +static void +dev_detach_ (void) +{ + gtk_widget_reparent (infos_[MIXGTK_DEVICES_WINDOW].widget, + GTK_WIDGET (dev_container_)); +} + +static void +on_nb_switch_ (GtkNotebook *notebook, GtkWidget *page, + guint page_num, gpointer user_data) +{ + if (!(infos_[MIXGTK_MIXAL_WINDOW].detached) + && (page != infos_[MIXGTK_MIXAL_WINDOW].widget)) + mixgtk_mixal_pop_status (); +} + + diff --git a/mixgtk/mixgtk_wm.h b/mixgtk/mixgtk_wm.h new file mode 100644 index 0000000..878eca6 --- /dev/null +++ b/mixgtk/mixgtk_wm.h @@ -0,0 +1,46 @@ +/* -*-c-*- ---------------- mixgtk_wm.h : + * Functions for window management + * ------------------------------------------------------------------ + * $Id: mixgtk_wm.h,v 1.5 2005/09/20 19:43:14 jao Exp $ + * ------------------------------------------------------------------ + * Copyright (C) 2001, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + + +#ifndef MIXGTK_WM_H +#define MIXGTK_WM_H + +#include "mixgtk.h" + +typedef enum { + MIXGTK_MIXVM_WINDOW, + MIXGTK_MIXAL_WINDOW, + MIXGTK_DEVICES_WINDOW +} mixgtk_window_id_t; + +extern gboolean +mixgtk_wm_init (void); + +extern void +mixgtk_wm_attach_window (mixgtk_window_id_t w); + +extern void +mixgtk_wm_detach_window (mixgtk_window_id_t w); + +#endif /* MIXGTK_WM_H */ + -- cgit v1.2.3