From 13884bea299129048c1912510292d1207f520323 Mon Sep 17 00:00:00 2001 From: jaortega Date: Fri, 9 Mar 2001 00:13:21 +0000 Subject: partial functionality implemented --- mixgtk/Makefile.am | 7 +- mixgtk/mixgtk.c | 39 ++- mixgtk/mixgtk.glade | 560 +++++++++++++++++++++++++---------------- mixgtk/mixgtk_cmd_dispatcher.c | 62 ++++- mixgtk/mixgtk_cmd_dispatcher.h | 12 +- mixgtk/mixgtk_device.c | 155 ++++++++++++ mixgtk/mixgtk_device.h | 42 ++++ mixgtk/mixgtk_gen_handlers.c | 20 +- mixgtk/mixgtk_gen_handlers.h | 5 +- mixgtk/mixgtk_mixvm.c | 220 ++++++++++++++++ mixgtk/mixgtk_mixvm.h | 75 ++++++ mixgtk/mixgtk_widgets.c | 38 ++- mixgtk/mixgtk_widgets.h | 18 +- 13 files changed, 975 insertions(+), 278 deletions(-) create mode 100644 mixgtk/mixgtk_device.c create mode 100644 mixgtk/mixgtk_device.h create mode 100644 mixgtk/mixgtk_mixvm.c create mode 100644 mixgtk/mixgtk_mixvm.h diff --git a/mixgtk/Makefile.am b/mixgtk/Makefile.am index bb1881f..881ec99 100644 --- a/mixgtk/Makefile.am +++ b/mixgtk/Makefile.am @@ -17,4 +17,9 @@ LDADD = $(top_builddir)/mixlib/libmix.a bin_PROGRAMS = mixgtk mixgtk_SOURCES = mixgtk.c mixgtk_gen_handlers.h mixgtk_gen_handlers.c \ mixgtk_cmd_dispatcher.h mixgtk_cmd_dispatcher.c \ - mixgtk_widgets.h mixgtk_widgets.c + mixgtk_widgets.h mixgtk_widgets.c \ + mixgtk_device.h mixgtk_device.c \ + mixgtk_mixvm.h mixgtk_mixvm.c + + + diff --git a/mixgtk/mixgtk.c b/mixgtk/mixgtk.c index 01b57c0..1e4abf1 100644 --- a/mixgtk/mixgtk.c +++ b/mixgtk/mixgtk.c @@ -1,7 +1,7 @@ /* -*-c-*- -------------- mixgtk.c : * Main function of the mix gtk front-end * ------------------------------------------------------------------ - * Last change: Time-stamp: "01/02/27 01:55:13 jose" + * Last change: Time-stamp: "01/03/07 23:14:56 jose" * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * @@ -26,25 +26,46 @@ #include #include "mixgtk_widgets.h" #include "mixgtk_cmd_dispatcher.h" +#include "mixgtk_device.h" +#include "mixgtk_mixvm.h" int main(int argc, char *argv[]) { const gchar *glade_file = "mixgtk.glade"; + mix_vm_t *vm; gtk_init(&argc, &argv); mix_init_lib (); - if (!mixgtk_widget_factory_init (glade_file)) { - g_error ("Unable to initialise application (using %s)\n", glade_file); - return EXIT_FAILURE; - } + if (!mixgtk_widget_factory_init (glade_file)) + { + g_error ("Unable to initialise application (using %s)\n", glade_file); + return EXIT_FAILURE; + } - if (!mixgtk_cmd_dispatcher_init ()) { - g_error ("Unable to initialise application\n"); - return EXIT_FAILURE; - } + if (!mixgtk_cmd_dispatcher_init ()) + { + g_error ("Unable to initialise application (command dispatcher)\n"); + return EXIT_FAILURE; + } + + vm = mixgtk_cmd_dispatcher_get_vm (); + + if (!mixgtk_device_init (GTK_NOTEBOOK + (mixgtk_widget_factory_get (MIXGTK_WIDGET_DEVICE)), + vm)) + { + g_error ("Unable to initialise application (devices)\n"); + return EXIT_FAILURE; + } + + if (!mixgtk_mixvm_init (vm)) + { + g_error ("Unable to initialise application (mixvm widgets)\n"); + return EXIT_FAILURE; + } gtk_main(); diff --git a/mixgtk/mixgtk.glade b/mixgtk/mixgtk.glade index 0100ad4..188332e 100644 --- a/mixgtk/mixgtk.glade +++ b/mixgtk/mixgtk.glade @@ -9,8 +9,10 @@ pixmaps C False - True + False True + False + False @@ -161,60 +163,18 @@ GtkFixed mixvm_widget - 10 375 287 - - GtkCList - cells_clist - 128 - 64 - 225 - 208 - True - 2 - 80,80 - GTK_SELECTION_SINGLE - True - GTK_SHADOW_IN - - - GtkLabel - CList:title - label95 - - GTK_JUSTIFY_CENTER - False - 0.5 - 0.5 - 0 - 0 - - - - GtkLabel - CList:title - label96 - - GTK_JUSTIFY_CENTER - False - 0.5 - 0.5 - 0 - 0 - - - GtkEntry rJ_entry - 40 - 48 + 304 + 88 60 - 22 + 24 True - True + False True 0 - 00 23 @@ -224,11 +184,11 @@ GtkEntry rA_entry 40 - 8 + 24 118 22 True - True + False True 0 + 01 45 34 49 49 @@ -237,12 +197,12 @@ GtkEntry rX_entry - 232 - 8 + 248 + 24 118 22 True - True + False True 0 @@ -252,11 +212,11 @@ GtkEntry rI2_entry 40 - 120 + 144 60 22 True - True + False True 0 @@ -268,9 +228,9 @@ 40 88 60 - 22 + 24 True - True + False True 0 @@ -280,11 +240,11 @@ GtkEntry rI3_entry 40 - 152 + 200 60 22 True - True + False True 0 @@ -293,12 +253,12 @@ GtkEntry rI4_entry - 40 - 184 + 168 + 88 60 - 22 + 24 True - True + False True 0 @@ -307,12 +267,12 @@ GtkEntry rI5_entry - 40 - 216 + 168 + 144 60 22 True - True + False True 0 @@ -321,12 +281,12 @@ GtkEntry rI6_entry - 40 - 248 + 168 + 200 60 22 True - True + False True 0 @@ -334,12 +294,12 @@ GtkLabel - label99 + label100 8 - 50 + 91 31 16 - + GTK_JUSTIFY_CENTER False 0.5 @@ -350,12 +310,12 @@ GtkLabel - label100 + label102 8 - 91 + 200 31 16 - + GTK_JUSTIFY_CENTER False 0.5 @@ -368,7 +328,7 @@ GtkLabel label101 8 - 124 + 144 31 16 @@ -382,12 +342,28 @@ GtkLabel - label102 - 8 - 155 + label103 + 136 + 88 + 32 + 16 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + + + GtkLabel + label104 + 136 + 144 31 16 - + GTK_JUSTIFY_CENTER False 0.5 @@ -398,12 +374,12 @@ GtkLabel - label103 - 8 - 187 + label105 + 136 + 200 31 16 - + GTK_JUSTIFY_CENTER False 0.5 @@ -414,12 +390,12 @@ GtkLabel - label104 - 8 - 219 + label98 + 216 + 24 31 16 - + GTK_JUSTIFY_CENTER False 0.5 @@ -430,12 +406,12 @@ GtkLabel - label105 + label97 8 - 251 + 24 31 16 - + GTK_JUSTIFY_CENTER False 0.5 @@ -445,129 +421,122 @@ - GtkNotebook - devices_notebook - 380 - 10 - 252 - 262 - True - True - True - GTK_POS_TOP - False - 2 - 2 - False - - - GtkScrolledWindow - scrolledwindow45 - GTK_POLICY_NEVER - GTK_POLICY_ALWAYS - GTK_UPDATE_CONTINUOUS - GTK_UPDATE_CONTINUOUS - - - GtkText - text37 - True - False - - - + GtkHSeparator + hseparator1 + 8 + 232 + 377 + 16 + - - GtkLabel - Notebook:tab - label156 - - GTK_JUSTIFY_CENTER - False - 0.5 - 0.5 - 0 - 0 - + + GtkVSeparator + vseparator2 + 0 + 8 + 16 + 263 + - - GtkScrolledWindow - scrolledwindow46 - GTK_POLICY_NEVER - GTK_POLICY_ALWAYS - GTK_UPDATE_CONTINUOUS - GTK_UPDATE_CONTINUOUS + + GtkHSeparator + hseparator3 + 6 + 1 + 627 + 16 + - - GtkText - text38 - True - False - - - + + GtkVSeparator + vseparator3 + 626 + 8 + 16 + 267 + - - GtkLabel - Notebook:tab - label157 - - GTK_JUSTIFY_CENTER - False - 0.5 - 0.5 - 0 - 0 - + + GtkLabel + label99 + 272 + 88 + 31 + 16 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + - - GtkScrolledWindow - scrolledwindow47 - GTK_POLICY_NEVER - GTK_POLICY_ALWAYS - GTK_UPDATE_CONTINUOUS - GTK_UPDATE_CONTINUOUS + + GtkHSeparator + hseparator2 + 6 + 265 + 627 + 16 + - - GtkText - text39 - True - False - - - + + GtkLabel + label159 + 8 + 248 + 64 + 16 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + - - GtkLabel - Notebook:tab - label158 - - GTK_JUSTIFY_CENTER - False - 0.5 - 0.5 - 0 - 0 - + + GtkLabel + label158 + 128 + 248 + 64 + 16 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 - GtkVSeparator - vseparator1 - 360 - 8 - 16 - 264 + GtkLabel + label157 + 256 + 248 + 48 + 16 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 GtkLabel - label97 - 8 - 12 - 31 + elapsed_label + 64 + 248 + 48 16 - + GTK_JUSTIFY_CENTER False 0.5 @@ -578,12 +547,12 @@ GtkLabel - label98 - 200 - 11 - 31 + program_label + 184 + 248 + 56 16 - + GTK_JUSTIFY_CENTER False 0.5 @@ -593,56 +562,156 @@ - GtkRadioButton - lesser_radio - 136 - 40 - 35 - 24 - True - - False - True + GtkLabel + uptime_label + 296 + 248 + 72 + 16 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 GtkRadioButton equal_radio - 176 - 40 + 312 + 136 31 24 True + + toggled + on_cmp_e_toggled + Tue, 06 Mar 2001 21:22:04 GMT + False True + cmp_group GtkRadioButton greater_radio - 216 - 40 + 336 + 160 32 24 True + + toggled + on_cmp_g_toggled + Tue, 06 Mar 2001 21:21:40 GMT + False True + cmp_group GtkRadioButton - over_radio - 279 - 45 - 76 - 14 + lesser_radio + 288 + 160 + 35 + 24 + True + + toggled + on_cmp_l_toggled + Tue, 06 Mar 2001 21:21:51 GMT + + + False + True + cmp_group + + + + GtkVSeparator + vseparator1 + 376 + 10 + 16 + 263 + + + + GtkCheckButton + over_toggle + 296 + 200 + 72 + 24 True + + toggled + on_overflow_toggled + Tue, 06 Mar 2001 21:32:39 GMT + False True + + + GtkScrolledWindow + memory_scroll + 392 + 16 + 215 + 248 + GTK_POLICY_NEVER + GTK_POLICY_AUTOMATIC + GTK_UPDATE_CONTINUOUS + GTK_UPDATE_CONTINUOUS + + + GtkCList + memory_cells + 200 + 248 + True + 2 + 53,135 + GTK_SELECTION_SINGLE + True + GTK_SHADOW_IN + + + GtkLabel + CList:title + label165 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + + + GtkLabel + CList:title + label166 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + + @@ -658,6 +727,51 @@ 0 + + GtkNotebook + devices_notebook + 404 + 254 + True + True + True + GTK_POS_RIGHT + True + 2 + 2 + True + + + Placeholder + + + + GtkLabel + Notebook:tab + label156 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + + + + GtkLabel + Notebook:tab + devices_label + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + GtkVBox vbox2 @@ -795,7 +909,7 @@ START LDA 1000 GtkScrolledWindow - scrolledwindow48 + mixlog_scrolledwindow GTK_POLICY_NEVER GTK_POLICY_ALWAYS GTK_UPDATE_CONTINUOUS diff --git a/mixgtk/mixgtk_cmd_dispatcher.c b/mixgtk/mixgtk_cmd_dispatcher.c index c5fef58..dc64f2f 100644 --- a/mixgtk/mixgtk_cmd_dispatcher.c +++ b/mixgtk/mixgtk_cmd_dispatcher.c @@ -1,7 +1,7 @@ /* -*-c-*- -------------- mixgtk_cmd_dispatcher.c : * Implementation of the functions declared in mixgtk_cmd_dispatcher.h * ------------------------------------------------------------------ - * Last change: Time-stamp: "01/02/26 03:15:18 jose" + * Last change: Time-stamp: "01/03/07 23:17:54 jose" * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * @@ -26,6 +26,8 @@ #include #include #include "mixgtk_cmd_dispatcher.h" +#include "mixgtk_mixvm.h" + /* a mix vm command dispatcher */ struct mixgtk_dispatch_ @@ -61,7 +63,7 @@ global_pre_hook_ (mix_vm_cmd_dispatcher_t *dis, else { gtk_text_insert (GTK_TEXT (dis_data_.log), NULL, NULL, NULL, - _("*** Invalid command\n"), -1); + _("\n*** Invalid command ***\n"), -1); } } @@ -76,6 +78,25 @@ global_post_hook_ (mix_vm_cmd_dispatcher_t *dis, dis_data_.out_buffer, dis_data_.out_buffer_size); } rewind (dis_data_.out); + mixgtk_mixvm_update_vm_widgets (); +} + +static void +load_post_hook_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg, + gpointer data) +{ +} + +static void +run_post_hook_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg, + gpointer data) +{ +} + +static void +next_post_hook_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg, + gpointer data) +{ } @@ -98,14 +119,41 @@ mixgtk_cmd_dispatcher_init (void) if (!out) return FALSE; dis_data_.out = out; dis_data_.dispatcher = mix_vm_cmd_dispatcher_new (out, out); - mix_vm_cmd_dispatcher_global_pre_hook(dis_data_.dispatcher, - global_pre_hook_, NULL); - mix_vm_cmd_dispatcher_global_post_hook(dis_data_.dispatcher, - global_post_hook_, NULL); + mix_vm_cmd_dispatcher_global_pre_hook (dis_data_.dispatcher, + global_pre_hook_, NULL); + mix_vm_cmd_dispatcher_global_post_hook (dis_data_.dispatcher, + global_post_hook_, NULL); + 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); } return TRUE; } +/* dispatch an externally provided command */ +void +mixgtk_cmd_dispatcher_dispatch (const gchar *command) +{ + GtkWidget *entry = mixgtk_widget_factory_get (MIXGTK_WIDGET_PROMPT); + g_return_if_fail (command != NULL); + g_assert (entry != NULL); + gtk_entry_set_text (GTK_ENTRY (entry), command); + on_mixvm_cmd_entry_activate (entry, NULL); +} + +/* get the underlying vm */ +extern mix_vm_t * +mixgtk_cmd_dispatcher_get_vm (void) +{ + return (mix_vm_t *) mix_vm_cmd_dispatcher_get_vm (dis_data_.dispatcher); +} + /* process new command */ void on_mixvm_cmd_entry_activate (GtkWidget *w, gpointer e) @@ -115,3 +163,5 @@ on_mixvm_cmd_entry_activate (GtkWidget *w, gpointer e) mix_vm_cmd_dispatcher_dispatch_text (dis_data_.dispatcher, text); gtk_entry_set_text (GTK_ENTRY (w), ""); } + + diff --git a/mixgtk/mixgtk_cmd_dispatcher.h b/mixgtk/mixgtk_cmd_dispatcher.h index 0169a5d..b0beb17 100644 --- a/mixgtk/mixgtk_cmd_dispatcher.h +++ b/mixgtk/mixgtk_cmd_dispatcher.h @@ -1,7 +1,7 @@ /* -*-c-*- ---------------- mixgtk_cmd_dispatcher.h : * functions to access the command dispatcher * ------------------------------------------------------------------ - * Last change: Time-stamp: <01/02/25 17:24:28 jose> + * Last change: Time-stamp: <01/03/06 22:29:57 jose> * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * @@ -25,12 +25,20 @@ #ifndef MIXGTK_CMD_DISPATCHER_H #define MIXGTK_CMD_DISPATCHER_H +#include #include "mixgtk_widgets.h" /* initialise the command dispatcher */ extern gboolean -mixgtk_cmd_dispatcher_init (); +mixgtk_cmd_dispatcher_init (void); +/* dispatch an externally provided command */ +extern void +mixgtk_cmd_dispatcher_dispatch (const gchar *command); + +/* get the underlying vm */ +extern mix_vm_t * +mixgtk_cmd_dispatcher_get_vm (void); /* make gtk signal callbacks accessible to glade */ /* new command handler */ diff --git a/mixgtk/mixgtk_device.c b/mixgtk/mixgtk_device.c new file mode 100644 index 0000000..2e231a4 --- /dev/null +++ b/mixgtk/mixgtk_device.c @@ -0,0 +1,155 @@ +/* -*-c-*- ---------------- mixgtk_device.c : + * actual types for mixgtk devices + * ------------------------------------------------------------------ + * Last change: Time-stamp: <01/03/05 01:13:40 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + + +#define _GNU_SOURCE 1 + +#include +#include +#include "mixgtk_device.h" + +/* device container */ +static GtkNotebook *container_ = NULL; +/* virtual machine */ +static mix_vm_t *vm_ = NULL; + +/* a mixgtk device */ +struct mixgtk_device_t +{ + mix_device_t device; + char *buffer; + size_t buffer_len; + GtkText *widget; + gint pos; +}; + +/* callbacks for output devices */ +static gboolean +write_out_ (mix_device_t *dev, const mix_word_t *block) +{ + struct mixgtk_device_t *gtkdev; + + if (!((DEF_DEV_VTABLE_->write) (dev, block))) return FALSE; + gtkdev = (struct mixgtk_device_t *) dev; + if (gtkdev->buffer_len > 0) + { + gtk_text_insert (gtkdev->widget, NULL, NULL, NULL, + gtkdev->buffer, gtkdev->buffer_len); + rewind (mix_io_to_FILE (gtkdev->device.file)); + gtk_notebook_set_page (container_, gtkdev->pos); + gtk_widget_draw (GTK_WIDGET (container_), NULL); + } + return TRUE; +} + +static mix_device_vtable_t MIXGTK_OUT_VTABLE_; + +/* create a new mixgtk device */ +static struct mixgtk_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 && FMODES_[type] == mix_io_WRITE) + { + FILE *f; + dev = g_new (struct mixgtk_device_t, 1); + f = open_memstream (&(dev->buffer), &(dev->buffer_len)); + g_assert (f); + dev->device.file = mix_io_new (f); + dev->device.type = type; + dev->device.vtable = &MIXGTK_OUT_VTABLE_; + dev->widget = (GtkText *)gtk_text_new (NULL, NULL); + g_assert (dev->widget); + gtk_text_set_editable (dev->widget, FALSE); + } + return dev; +} + +/* connect a device */ +static void +mixgtk_device_connect_ (struct mixgtk_device_t *dev) +{ + static gint last_pos = 0; + GtkWidget *label = gtk_label_new (DEF_NAMES_[dev->device.type]); + GtkWidget *box = gtk_hbox_new (0, 0); + GtkWidget *scroll = gtk_vscrollbar_new (dev->widget->vadj); + g_assert (label); + g_assert (box); + gtk_box_pack_start (GTK_BOX (box), GTK_WIDGET (dev->widget), + TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (box), scroll, FALSE, FALSE, 0); + dev->pos = last_pos++; + gtk_notebook_insert_page (container_, box, label, dev->pos); + gtk_widget_show (box); + gtk_widget_show (label); + gtk_widget_show (scroll); + gtk_widget_show (GTK_WIDGET (dev->widget)); + gtk_widget_draw (GTK_WIDGET (container_), NULL); + (void) mix_vm_connect_device (vm_, (mix_device_t *)dev); +} + +/* init default devices */ +gboolean +mixgtk_device_init (GtkNotebook *container, mix_vm_t *vm) +{ + static mix_device_type_t def_types[] = { + mix_dev_CONSOLE, mix_dev_PRINTER, mix_dev_PAPER_TAPE, mix_dev_INVALID + }; + + gint k = 0; + + g_return_val_if_fail (container != NULL, FALSE); + g_return_val_if_fail (vm != NULL, FALSE); + container_ = container; + vm_ = vm; + + /* remove dummy page from container */ + gtk_notebook_remove_page (container_, 0); + + /* initialise vtables */ + MIXGTK_OUT_VTABLE_.write = write_out_; + MIXGTK_OUT_VTABLE_.read = DEF_DEV_VTABLE_->read; + MIXGTK_OUT_VTABLE_.ioc = DEF_DEV_VTABLE_->ioc; + MIXGTK_OUT_VTABLE_.busy = DEF_DEV_VTABLE_->busy; + + /* connect default devices */ + while (def_types[k] != mix_dev_INVALID) + { + struct mixgtk_device_t *dev = mixgtk_device_new_ (def_types[k]); + if (dev != NULL) + mixgtk_device_connect_ (dev); + ++k; + } + + /* set to first page */ + gtk_notebook_set_page (container_, 0); + + return TRUE; +} + +/* connect a new (file-based) device */ +gboolean +mixgtk_device_connect (mix_device_type_t type, const gchar *name); diff --git a/mixgtk/mixgtk_device.h b/mixgtk/mixgtk_device.h new file mode 100644 index 0000000..7c21238 --- /dev/null +++ b/mixgtk/mixgtk_device.h @@ -0,0 +1,42 @@ +/* -*-c-*- ---------------- mixgtk_device.h : + * Block devices used by mixgtk + * ------------------------------------------------------------------ + * Last change: Time-stamp: <01/03/04 23:43:59 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + + +#ifndef MIXGTK_DEVICE_H +#define MIXGTK_DEVICE_H + +#include +#include +#include + +/* init default devices */ +extern gboolean +mixgtk_device_init (GtkNotebook *container, mix_vm_t *vm); + + +/* connect a new (file-based) device */ +extern gboolean +mixgtk_device_connect (mix_device_type_t type, const gchar *name); + +#endif /* MIXGTK_DEVICE_H */ + diff --git a/mixgtk/mixgtk_gen_handlers.c b/mixgtk/mixgtk_gen_handlers.c index e472341..8f0c07c 100644 --- a/mixgtk/mixgtk_gen_handlers.c +++ b/mixgtk/mixgtk_gen_handlers.c @@ -1,7 +1,7 @@ /* -*-c-*- -------------- mixgtk_gen_handlers.c : * Implementation of the functions declared in mixgtk_gen_handlers.h * ------------------------------------------------------------------ - * Last change: Time-stamp: "01/02/23 00:36:31 jose" + * Last change: Time-stamp: "01/03/07 23:25:10 jose" * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * @@ -21,8 +21,9 @@ * */ - +#include #include "mixgtk_gen_handlers.h" +#include "mixgtk_cmd_dispatcher.h" void on_main_window_destroy (GtkWidget *w, gpointer data) @@ -34,8 +35,12 @@ static void on_file_open_ok_ (GtkWidget *w, gpointer fs) { const gchar *file = gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs)); - g_print ("File %s selected\n", file); + gchar *command = g_strdup_printf ("%s %s", + mix_vm_command_to_string (MIX_CMD_LOAD), + file); gtk_widget_destroy (GTK_WIDGET (fs)); + mixgtk_cmd_dispatcher_dispatch (command); + g_free (command); } static void @@ -65,15 +70,6 @@ on_file_open_activate (GtkWidget *w, gpointer data) void on_file_exit_activate (GtkWidget *w, gpointer data) { - g_message ("File_exit activated"); gtk_main_quit (); } -void -on_debug_activate (GtkWidget *w, gpointer data) -{ -} - - - - diff --git a/mixgtk/mixgtk_gen_handlers.h b/mixgtk/mixgtk_gen_handlers.h index e1aed47..5b1d788 100644 --- a/mixgtk/mixgtk_gen_handlers.h +++ b/mixgtk/mixgtk_gen_handlers.h @@ -1,7 +1,7 @@ /* -*-c-*- ---------------- mixgtk_gen_handlers.h : * general signal handlers declarations * ------------------------------------------------------------------ - * Last change: Time-stamp: <01/02/23 00:36:35 jose> + * Last change: Time-stamp: <01/03/07 23:23:25 jose> * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * @@ -36,8 +36,7 @@ on_file_open_activate (GtkWidget *w, gpointer data); extern void on_file_exit_activate (GtkWidget *w, gpointer data); -extern void -on_debug_activate (GtkWidget *w, gpointer data); + diff --git a/mixgtk/mixgtk_mixvm.c b/mixgtk/mixgtk_mixvm.c new file mode 100644 index 0000000..ba5023a --- /dev/null +++ b/mixgtk/mixgtk_mixvm.c @@ -0,0 +1,220 @@ +/* -*-c-*- -------------- mixgtk_mixvm.c : + * Implementation of the functions declared in mixgtk_mixvm.h + * ------------------------------------------------------------------ + * Last change: Time-stamp: "01/03/08 23:22:49 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include +#include "mixgtk_widgets.h" +#include "mixgtk_mixvm.h" + +/* register widgets */ +#define REGISTER_NO_ (MIXGTK_WIDGET_rI6 - MIXGTK_WIDGET_rA + 1) + +static GtkEntry *reg_entries_[REGISTER_NO_]; +static GtkToggleButton *over_button_; +static GtkToggleButton *cmp_buttons_[3]; +static GtkCList *memory_; +static mix_vm_t *vm_; + + +static void +update_register_ (mixgtk_widget_id_t reg) +{ + static gchar BUFFER[20]; + switch (reg) + { + case MIXGTK_WIDGET_rA: + mix_word_print_to_buffer (mix_vm_get_rA (vm_), BUFFER); + break; + case MIXGTK_WIDGET_rX: + mix_word_print_to_buffer (mix_vm_get_rX (vm_), BUFFER); + break; + case MIXGTK_WIDGET_rJ: + 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: + mix_short_print_to_buffer (mix_vm_get_rI (vm_, + reg - MIXGTK_WIDGET_rI1 + 1), + BUFFER); + break; + default: + g_assert_not_reached (); + } + gtk_entry_set_text (reg_entries_[reg - MIXGTK_WIDGET_rA], BUFFER); +} + + +static void +on_mem_adj_change_ (GtkAdjustment *adj) +{ + mixgtk_mixvm_update_cells (); +} + + +/* initialise the mixvm widgets */ +gboolean +mixgtk_mixvm_init (mix_vm_t *vm) +{ + int k; + gchar *text[] = {"", ""}; + GtkWidget *scrol; + GtkAdjustment *adj; + + g_return_val_if_fail (vm != NULL, FALSE); + vm_ = vm; + + for (k = 0; k < REGISTER_NO_; ++k) + { + reg_entries_[k] = + GTK_ENTRY (mixgtk_widget_factory_get (MIXGTK_WIDGET_rA + k)); + g_return_val_if_fail (reg_entries_[k] != NULL, FALSE); + } + + over_button_ = + GTK_TOGGLE_BUTTON (mixgtk_widget_factory_get (MIXGTK_WIDGET_OVER)); + g_return_val_if_fail (over_button_ != NULL, FALSE); + + for (k = 0; k < 3; ++k) + { + cmp_buttons_[k] = + GTK_TOGGLE_BUTTON (mixgtk_widget_factory_get (MIXGTK_WIDGET_CMP_L +k)); + g_return_val_if_fail (cmp_buttons_[k] != NULL, FALSE); + } + + memory_ = GTK_CLIST (mixgtk_widget_factory_get (MIXGTK_WIDGET_CELLS)); + g_return_val_if_fail (memory_ != NULL, FALSE); + gtk_clist_set_column_justification (memory_, 0, GTK_JUSTIFY_CENTER); + gtk_clist_set_column_justification (memory_, 1, GTK_JUSTIFY_CENTER); + gtk_clist_freeze (memory_); + for (k = 0; k< MIX_VM_CELL_NO; ++k) + { + gchar buffer[20]; + sprintf (buffer, "%04d", k); + text[0] = buffer; + gtk_clist_append (memory_, text); + } + gtk_clist_thaw (memory_); + + scrol = mixgtk_widget_factory_get_by_name ("memory_scroll"); + adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrol)); + gtk_signal_connect (GTK_OBJECT (adj), "value_changed", + GTK_SIGNAL_FUNC (on_mem_adj_change_), NULL); + + mixgtk_mixvm_update_vm_widgets (); + + return TRUE; +} + + +/* 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_ != NULL); + gtk_toggle_button_set_active (over_button_, + mix_vm_get_overflow (vm_)); +} + +/* update the comparison flag */ +void +mixgtk_mixvm_update_cmp (void) +{ + gint toggle; + 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]; + gint k = 0; + + gtk_clist_freeze (memory_); + + while (gtk_clist_row_is_visible (memory_, k) == GTK_VISIBILITY_NONE) ++k; + while (gtk_clist_row_is_visible (memory_, k) != GTK_VISIBILITY_NONE) + { + mix_word_print_to_buffer (mix_vm_get_addr_contents (vm_, k), BUFFER); + gtk_clist_set_text (memory_, k, 1, BUFFER); + ++k; + } + + gtk_clist_thaw (memory_); +} + + +/* update all mixvm widgets */ +void +mixgtk_mixvm_update_vm_widgets (void) +{ + mixgtk_mixvm_update_registers (); + mixgtk_mixvm_update_over_toggle (); + mixgtk_mixvm_update_cmp (); + mixgtk_mixvm_update_cells (); +} + + +/* 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); +} + + diff --git a/mixgtk/mixgtk_mixvm.h b/mixgtk/mixgtk_mixvm.h new file mode 100644 index 0000000..a2699cb --- /dev/null +++ b/mixgtk/mixgtk_mixvm.h @@ -0,0 +1,75 @@ +/* -*-c-*- ---------------- mixgtk_mixvm.h : + * Functions dealing with the mixvm widgets + * ------------------------------------------------------------------ + * Last change: Time-stamp: <01/03/07 23:58:35 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + + +#ifndef MIXGTK_MIXVM_H +#define MIXGTK_MIXVM_H + +#include + +/* initialise the mixvm widgets */ +extern gboolean +mixgtk_mixvm_init (mix_vm_t *vm); + +/* 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); + +/* update all mixvm widgets */ +extern void +mixgtk_mixvm_update_vm_widgets (void); + +/* callbacks */ +/* cmp flag changed */ +extern void +on_cmp_e_toggled (GtkWidget *widget, gpointer data); + +extern void +on_cmp_g_toggled (GtkWidget *widget, gpointer data); + +extern void +on_cmp_l_toggled (GtkWidget *widget, gpointer data); + +extern void +on_overflow_toggled (GtkWidget *widget, gpointer data); + +extern void +on_memory_cells_scroll_vertical (GtkWidget *widget, GtkScrollType, + gfloat, gpointer); + + + +#endif /* MIXGTK_MIXVM_H */ + diff --git a/mixgtk/mixgtk_widgets.c b/mixgtk/mixgtk_widgets.c index aa06643..276a6fb 100644 --- a/mixgtk/mixgtk_widgets.c +++ b/mixgtk/mixgtk_widgets.c @@ -1,7 +1,7 @@ /* -*-c-*- -------------- mixgtk_widgets.c : * Implementation of the functions declared in mixgtk_widgets.h * ------------------------------------------------------------------ - * Last change: Time-stamp: "01/02/26 02:57:02 jose" + * Last change: Time-stamp: "01/03/08 22:32:35 jose" * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * @@ -34,11 +34,29 @@ static const gchar *names_[] = { "main_window", "word_dialog", "command_prompt", - "command_log" + "command_log", + "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", + "devices_notebook", + NULL }; #define WIDGET_NO_ (sizeof (names_) / sizeof (names_[0])) + + /* create a new factory from an xml glade file */ gboolean mixgtk_widget_factory_init (const char *glade_file) @@ -47,6 +65,7 @@ mixgtk_widget_factory_init (const char *glade_file) xml_ = glade_xml_new (glade_file, NULL); if (!xml_) return FALSE; glade_xml_signal_autoconnect (xml_); + return TRUE; } @@ -58,14 +77,11 @@ mixgtk_widget_factory_get (mixgtk_widget_id_t widget) return glade_xml_get_widget (xml_, names_[widget]); } -/* update a widget from a virtual machine */ -extern void -mixgtk_widget_factory_update_widget (mixgtk_widget_id_t widget, - const mix_vm_t *vm); - -/* update the virtual machine from a widget */ -extern void -mixgtk_widget_factory_update_vm (mixgtk_widget_id_t widget, - mix_vm_t *vm); +/* Get a widget by name */ +GtkWidget * +mixgtk_widget_factory_get_by_name (const gchar *name) +{ + return glade_xml_get_widget (xml_, name); +} diff --git a/mixgtk/mixgtk_widgets.h b/mixgtk/mixgtk_widgets.h index 60781e4..26e8b4d 100644 --- a/mixgtk/mixgtk_widgets.h +++ b/mixgtk/mixgtk_widgets.h @@ -1,7 +1,7 @@ /* -*-c-*- ---------------- mixgtk_widgets.h : * glade-based factory of mixvm widgets * ------------------------------------------------------------------ - * Last change: Time-stamp: <01/02/25 12:51:58 jose> + * Last change: Time-stamp: <01/03/08 22:27:01 jose> * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * @@ -43,7 +43,9 @@ typedef enum { MIXGTK_WIDGET_rI4, MIXGTK_WIDGET_rI5, MIXGTK_WIDGET_rI6, - MIXGTK_WIDGET_CMP, + MIXGTK_WIDGET_CMP_L, + MIXGTK_WIDGET_CMP_E, + MIXGTK_WIDGET_CMP_G, MIXGTK_WIDGET_OVER, MIXGTK_WIDGET_CELLS, MIXGTK_WIDGET_DEVICE, @@ -60,15 +62,9 @@ mixgtk_widget_factory_init (const char *glade_file); extern GtkWidget * mixgtk_widget_factory_get (mixgtk_widget_id_t widget); -/* update a widget from a virtual machine */ -extern void -mixgtk_widget_factory_update_widget (mixgtk_widget_id_t widget, - const mix_vm_t *vm); - -/* update the virtual machine from a widget */ -extern void -mixgtk_widget_factory_update_vm (mixgtk_widget_id_t widget, - mix_vm_t *vm); +/* Get a widget by name */ +extern GtkWidget * +mixgtk_widget_factory_get_by_name (const gchar *name); #endif /* MIXGTK_WIDGETS_H */ -- cgit v1.2.3