diff options
author | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2001-05-06 21:38:13 +0000 |
---|---|---|
committer | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2001-05-06 21:38:13 +0000 |
commit | 070635cb6e0b42c7a485189d1a58db04482de0f8 (patch) | |
tree | b814420bed82cf36ba64bbd44841d63eb2ded1e4 /mixgtk | |
parent | 6c118b8f8965a5fbb602ad556b584f6f8c0c26c0 (diff) | |
download | mdk-070635cb6e0b42c7a485189d1a58db04482de0f8.tar.gz mdk-070635cb6e0b42c7a485189d1a58db04482de0f8.tar.bz2 |
support for gtk binary devices added
Diffstat (limited to 'mixgtk')
-rw-r--r-- | mixgtk/mixgtk_device.c | 146 |
1 files changed, 95 insertions, 51 deletions
diff --git a/mixgtk/mixgtk_device.c b/mixgtk/mixgtk_device.c index faf3c3b..2a31afe 100644 --- a/mixgtk/mixgtk_device.c +++ b/mixgtk/mixgtk_device.c @@ -1,7 +1,7 @@ /* -*-c-*- ---------------- mixgtk_device.c : * actual types for mixgtk devices * ------------------------------------------------------------------ - * Last change: Time-stamp: <01/04/03 00:09:46 jose> + * Last change: Time-stamp: <2001-05-06 23:34:51 jao> * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * @@ -24,6 +24,7 @@ #include <stdio.h> #include <mixlib/xmix_device.h> +#include "mixgtk.h" #include "mixgtk_device.h" /* device container */ @@ -35,85 +36,113 @@ static mix_vm_t *vm_ = NULL; struct mixgtk_device_t { mix_device_t device; - gchar *buffer; GtkText *widget; gint pos; }; /* callbacks for output devices */ -static gboolean -write_out_ (mix_device_t *dev, const mix_word_t *block) +static void +write_char_ (struct mixgtk_device_t *dev, const mix_word_t *block) { - struct mixgtk_device_t *gtkdev = (struct mixgtk_device_t *) dev; + enum {MAX_BLOCK = 16, BUFF_SIZE = MAX_BLOCK * 5 + 2}; + static gchar BUFFER[BUFF_SIZE]; guint k, j; - - for (k = 0; k < SIZES_[dev->type]; k++) + + 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); - gtkdev->buffer[5 * k + j - 1] = mix_char_to_ascii (ch); + BUFFER[5 * k + j - 1] = mix_char_to_ascii (ch); } - gtk_text_insert (gtkdev->widget, NULL, NULL, NULL, gtkdev->buffer, -1); + BUFFER[5 * k] = '\n'; + BUFFER[5 * k + 1] = '\0'; + + gtk_text_insert (dev->widget, NULL, NULL, NULL, BUFFER, -1); + +} + +static void +write_bin_ (struct mixgtk_device_t *dev, const mix_word_t *block) +{ + enum {BUFF_SIZE = 17, STEP = 10}; + static gchar BUFFER[BUFF_SIZE] = { 0 }; + guint k; + + for (k = 0; k < SIZES_[dev->device.type]; k++) + { + mix_word_print_to_buffer (block[k], BUFFER); + gtk_text_insert (dev->widget, NULL, NULL, NULL, BUFFER, -1); + gtk_text_insert (dev->widget, NULL, NULL, NULL, + ((k+1)%STEP != 0) ? " " : "\n", -1); + } +} + +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_ (gtkdev, block); + gtk_notebook_set_page (container_, gtkdev->pos); return TRUE; } + static gboolean -read_out_ (mix_device_t *dev, mix_word_t *block) +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 && !(DEF_DEV_VTABLE_->read)(dev, block)) + return FALSE; + + if (MODES_[dev->type] == mix_dev_CHAR) write_char_ (gtkdev, block); + else write_bin_ (gtkdev, block); + + gtk_notebook_set_page (container_, gtkdev->pos); + return TRUE; } static gboolean -ioc_out_ (mix_device_t *dev, mix_short_t cmd) +ioc_ (mix_device_t *dev, mix_short_t cmd) { - return TRUE; + return (DEF_DEV_VTABLE_->ioc)(dev, cmd); } static gboolean -busy_out_ (const mix_device_t *dev) +busy_ (const mix_device_t *dev) { - return TRUE; + return (DEF_DEV_VTABLE_->busy)(dev); } -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); +static mix_device_vtable_t MIXGTK_VTABLE_ = {write_, read_, ioc_, busy_}; - if (MODES_[type] == mix_dev_CHAR && FMODES_[type] == mix_io_WRITE) - { - dev = g_new (struct mixgtk_device_t, 1); - dev->device.file = NULL; - dev->device.type = type; - dev->device.vtable = &MIXGTK_OUT_VTABLE_; - dev->buffer = g_new (gchar, (SIZES_[type] * 5 + 2)); - dev->buffer[SIZES_[type] * 5] = '\n'; - dev->buffer[SIZES_[type] * 5 + 1] = '\0'; - dev->widget = (GtkText *)gtk_text_new (NULL, NULL); - g_assert (dev->widget); - gtk_text_set_editable (dev->widget, FALSE); - } - return dev; -} -/* connect a device */ +/* create the gui part of the device */ static void -mixgtk_device_connect_ (struct mixgtk_device_t *dev) +mixgtk_device_construct_gui_ (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); + GtkWidget *scroll = NULL; + g_assert (label); g_assert (box); + + dev->widget = (GtkText *)gtk_text_new (NULL, NULL); + g_assert (dev->widget); + gtk_text_set_editable (dev->widget, FALSE); + + scroll = gtk_vscrollbar_new (dev->widget->vadj); 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); @@ -124,7 +153,27 @@ mixgtk_device_connect_ (struct mixgtk_device_t *dev) 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); +} + +/* create a new mixgtk device */ +static mix_device_t * +mixgtk_device_new_ (mix_device_type_t type) +{ + struct mixgtk_device_t *dev = NULL; + gchar *name = NULL; + + g_return_val_if_fail (type < mix_dev_INVALID, NULL); + + dev = g_new (struct mixgtk_device_t, 1); + name = g_strconcat (g_get_home_dir(), "/", + MIXGTK_FILES_DIR, "/", DEF_NAMES_[type], NULL); + construct_device_with_name_ (&dev->device, type, name); + g_free (name); + dev->device.vtable = &MIXGTK_VTABLE_; + + mixgtk_device_construct_gui_ (dev); + + return (mix_device_t *)dev; } /* init default devices */ @@ -132,7 +181,7 @@ 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 + mix_dev_CONSOLE, mix_dev_INVALID }; gint k = 0; @@ -145,18 +194,13 @@ mixgtk_device_init (GtkNotebook *container, mix_vm_t *vm) /* remove dummy page from container */ gtk_notebook_remove_page (container_, 0); - /* initialise vtables */ - MIXGTK_OUT_VTABLE_.write = write_out_; - MIXGTK_OUT_VTABLE_.read = read_out_; - MIXGTK_OUT_VTABLE_.ioc = ioc_out_; - MIXGTK_OUT_VTABLE_.busy = busy_out_; + mix_vm_set_device_factory (vm, mixgtk_device_new_); /* 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); + struct mix_device_t *dev = mixgtk_device_new_ (def_types[k]); + if (dev != NULL) mix_vm_connect_device (vm, dev); ++k; } |