From 6af55349a608242f7eccb89289c19dadf8b047fe Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Fri, 11 Jun 2004 23:35:59 +0000 Subject: support for terminal device input in the form of a new dialog. --- mixgtk/mixgtk.glade | 147 ++++++++++++++++++++++++++++++++++++++++++++++++ mixgtk/mixgtk_device.c | 128 ++++++++++++++++++++++++++++------------- mixgtk/mixgtk_widgets.c | 19 ++++--- mixgtk/mixgtk_widgets.h | 11 ++-- 4 files changed, 252 insertions(+), 53 deletions(-) (limited to 'mixgtk') diff --git a/mixgtk/mixgtk.glade b/mixgtk/mixgtk.glade index b3021ca..8c8d137 100644 --- a/mixgtk/mixgtk.glade +++ b/mixgtk/mixgtk.glade @@ -5116,4 +5116,151 @@ + + GtkDialog + input_dialog + False + + destroy + gtk_true + Fri, 11 Jun 2004 20:59:50 GMT + + + delete_event + gtk_true + Fri, 11 Jun 2004 21:00:03 GMT + + + destroy_event + gtk_true + Fri, 11 Jun 2004 21:00:51 GMT + + Terminal input + GTK_WINDOW_POPUP + GTK_WIN_POS_CENTER + True + 510 + False + False + False + + + GtkVBox + Dialog:vbox + dialog-vbox12 + False + 0 + + + GtkHBox + Dialog:action_area + dialog-action_area12 + 1 + True + 5 + + 0 + True + True + GTK_PACK_END + + + + GtkHButtonBox + hbuttonbox11 + GTK_BUTTONBOX_END + 0 + 85 + 27 + 7 + 0 + + 0 + True + True + + + + GtkButton + input_ok_button + True + True + + clicked + on_input_ok_clicked + Fri, 11 Jun 2004 21:01:32 GMT + + + GTK_RELIEF_NORMAL + + + + GtkButton + input_clear_button + True + True + + clicked + on_input_clear_clicked + Fri, 11 Jun 2004 21:01:56 GMT + + + GTK_RELIEF_NORMAL + + + + + + GtkVBox + vbox6 + 5 + True + 0 + + 5 + True + True + + + + GtkLabel + label240 + + GTK_JUSTIFY_LEFT + False + 0.5 + 0.5 + 0 + 0 + + 2 + True + True + + + + + GtkEntry + input_entry + True + True + + activate + on_input_entry_activate + Fri, 11 Jun 2004 23:30:53 GMT + + True + True + 70 + + + 4 + True + True + + + + + + diff --git a/mixgtk/mixgtk_device.c b/mixgtk/mixgtk_device.c index 3c55021..5ba3f9f 100644 --- a/mixgtk/mixgtk_device.c +++ b/mixgtk/mixgtk_device.c @@ -1,24 +1,24 @@ /* -*-c-*- ---------------- mixgtk_device.c : * actual types for mixgtk devices * ------------------------------------------------------------------ - * $Id: mixgtk_device.c,v 1.19 2002/04/10 23:39:40 jao Exp $ + * $Id: mixgtk_device.c,v 1.20 2004/06/11 23:35:59 jao Exp $ * ------------------------------------------------------------------ - * Copyright (C) 2001, 2002 Free Software Foundation, Inc. - * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * + * */ @@ -45,6 +45,9 @@ static GtkNotebook *container_ = 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 @@ -98,9 +101,9 @@ write_char_ (struct mixgtk_device_t *dev, const mix_word_t *block) BUFFER[5 * k] = '\n'; BUFFER[5 * k + 1] = '\0'; - + gtk_text_insert (GTK_TEXT (dev->widget), NULL, NULL, NULL, BUFFER, -1); - + } static const gchar * @@ -121,16 +124,16 @@ static void write_bin_ (struct mixgtk_bin_device_t *dev, const mix_word_t *block) { static gchar *DEFTEXT[BIN_DEV_COL_] = { "0", "0", "0", "0", "0" }; - + guint k, col, row; gboolean dec = FALSE; - + GtkCList *list = GTK_CLIST (dev->gtk_device.widget); - + dec = IS_DEC(decs_, dev->gtk_device.device.type); gtk_clist_freeze (list); - + for (k = 0; k < SIZES_[dev->gtk_device.device.type]; k++) { row = dev->last_insert / BIN_DEV_COL_; @@ -139,14 +142,14 @@ write_bin_ (struct mixgtk_bin_device_t *dev, const mix_word_t *block) { int j; mix_word_t *words = g_new (mix_word_t, 5); - gtk_clist_append (list, DEFTEXT); + gtk_clist_append (list, DEFTEXT); for (j = 0; j < 5; ++j) words[j] = block[k + j]; gtk_clist_set_row_data_full (list, row, (gpointer)words, g_free); } gtk_clist_set_text (list, row, col, get_word_string_ (block[k], dec)); dev->last_insert++; } - + gtk_clist_thaw (list); } @@ -157,14 +160,14 @@ redraw_bin_device_ (struct mixgtk_bin_device_t *dev) gboolean dec = FALSE; mix_word_t *words = NULL; GtkCList *list; - + if (!dev) return; - + list = GTK_CLIST (dev->gtk_device.widget); dec = IS_DEC(decs_, dev->gtk_device.device.type); gtk_clist_freeze (list); - + for (k = 0; k < dev->last_insert; ++k) { row = k / BIN_DEV_COL_; @@ -173,52 +176,80 @@ redraw_bin_device_ (struct mixgtk_bin_device_t *dev) words = gtk_clist_get_row_data (list, row); gtk_clist_set_text (list, row, col, get_word_string_ (words[col], dec)); } - + gtk_clist_thaw (list); } - + 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_page (container_, gtkdev->pos); return TRUE; } +static gboolean +read_cons_ (mix_word_t *block) +{ + gchar *text; + size_t i, j; -static gboolean + 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_widget_show (input_dlg_); + gtk_main (); /* wait until dialog closes */ + 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_page (container_, gtkdev->pos); return TRUE; } -static gboolean +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) +busy_ (const mix_device_t *dev) { return (DEF_DEV_VTABLE_->busy)(dev); } @@ -270,7 +301,7 @@ mixgtk_device_construct_gui_ (struct mixgtk_device_t *dev) gint k; struct mixgtk_bin_device_t *bindev = (struct mixgtk_bin_device_t *)dev; - + bindev->scroll = gtk_scrolled_window_new (NULL, NULL); g_assert (bindev->scroll); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (bindev->scroll), @@ -287,7 +318,7 @@ mixgtk_device_construct_gui_ (struct mixgtk_device_t *dev) gtk_notebook_insert_page (container_, bindev->scroll, label, dev->pos); gtk_widget_show (bindev->scroll); } - + gtk_widget_show (label); gtk_widget_set_style (dev->widget, gtk_widget_get_style (GTK_WIDGET (container_))); @@ -300,7 +331,7 @@ 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) @@ -367,7 +398,7 @@ gboolean mixgtk_device_init (GtkNotebook *container, mix_vm_t *vm) { gint k = 0; - + g_return_val_if_fail (container != NULL, FALSE); g_return_val_if_fail (vm != NULL, FALSE); container_ = container; @@ -376,6 +407,7 @@ mixgtk_device_init (GtkNotebook *container, mix_vm_t *vm) devdlg_ = NULL; devdir_dlg_ = NULL; devdir_entry_ = NULL; + input_dlg_ = NULL; dtoggle_ = NULL; wtoggle_ = NULL; combo_ = NULL; @@ -384,11 +416,11 @@ mixgtk_device_init (GtkNotebook *container, mix_vm_t *vm) gtk_notebook_remove_page (container_, 0); 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_)); - + /* re-create existing devices */ for (k = 0; k < mix_dev_INVALID; ++k) { @@ -403,7 +435,7 @@ mixgtk_device_init (GtkNotebook *container, mix_vm_t *vm) /* set to first page */ gtk_notebook_set_page (container_, 0); - + return TRUE; } @@ -411,11 +443,11 @@ 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)) { if (dec) SET_DEC (decs_, dev); @@ -423,7 +455,7 @@ mixgtk_device_set_format (mix_device_type_t dev, gboolean dec) redraw_bin_device_ ((struct mixgtk_bin_device_t *) mix_vm_get_device (vm_, dev)); } - + } @@ -445,7 +477,7 @@ init_devform_ (void) { GList *names = NULL; int k; - + devdlg_ = mixgtk_widget_factory_get_dialog (MIXGTK_DEVFORM_DIALOG); g_assert (devdlg_); dtoggle_ = mixgtk_widget_factory_get_child_by_name @@ -457,7 +489,7 @@ init_devform_ (void) combo_ = mixgtk_widget_factory_get_child_by_name (MIXGTK_DEVFORM_DIALOG, "dev_combo"); g_assert (combo_); - + for (k = 0; k <= LAST_BIN_DEV_; ++k) names = g_list_append (names, (gchar *)DEF_NAMES_[k]); gtk_combo_set_popdown_strings (GTK_COMBO (combo_), names); @@ -482,7 +514,6 @@ on_devform_activate () on_deventry_changed (); } - void on_decradio_toggled (GtkToggleButton *button) { @@ -570,3 +601,22 @@ on_devdir_ok_clicked () mixgtk_cmd_dispatcher_dispatch (cmd); g_free (cmd); } + +void +on_input_ok_clicked () +{ + gtk_widget_hide (input_dlg_); + gtk_main_quit (); +} + +void +on_input_clear_clicked () +{ + gtk_entry_set_text (input_dlg_entry_, ""); +} + +void +on_input_entry_activate () +{ + on_input_ok_clicked (); +} diff --git a/mixgtk/mixgtk_widgets.c b/mixgtk/mixgtk_widgets.c index 1cdbee2..9ff76a6 100644 --- a/mixgtk/mixgtk_widgets.c +++ b/mixgtk/mixgtk_widgets.c @@ -3,22 +3,22 @@ * ------------------------------------------------------------------ * Last change: Time-stamp: "2001-04-29 14:32:17 jao" * ------------------------------------------------------------------ - * Copyright (C) 2001 Free Software Foundation, Inc. - * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * + * */ @@ -43,6 +43,7 @@ static const gchar * dnames_[] = { "devform_dialog", "external_dialog", "symbols_dialog", + "input_dialog", "devdir_dialog" }; @@ -134,9 +135,9 @@ gboolean mixgtk_widget_factory_init (void) { gboolean split = mixgtk_config_is_split (); - + about_ = NULL; - + if (!file_) { const gchar *glade_file = GLADE_FILE; @@ -152,9 +153,9 @@ mixgtk_widget_factory_init (void) gint k; for (k = 0; k < DLG_NO_; ++k) if (xml_[k]) xml_[k] = NULL; } - + split_ = split; - + dnames_[MIXGTK_MAIN] = split_? SPLIT_MAIN_NAME_ : MAIN_NAME_; init_xml_ (MIXGTK_MAIN); diff --git a/mixgtk/mixgtk_widgets.h b/mixgtk/mixgtk_widgets.h index a38d4e9..6d84fc5 100644 --- a/mixgtk/mixgtk_widgets.h +++ b/mixgtk/mixgtk_widgets.h @@ -3,22 +3,22 @@ * ------------------------------------------------------------------ * Last change: Time-stamp: <2001-04-27 23:32:16 jao> * ------------------------------------------------------------------ - * Copyright (C) 2001 Free Software Foundation, Inc. - * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * + * */ @@ -43,6 +43,7 @@ typedef enum { 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 } mixgtk_dialog_id_t; -- cgit v1.2.3