From 119a5240f57ded266447b485e5a7c0eec6dd67f8 Mon Sep 17 00:00:00 2001 From: jaortega Date: Mon, 26 Feb 2001 23:16:00 +0000 Subject: gtk front-end files --- mixgtk/mixgtk_cmd_dispatcher.c | 117 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 mixgtk/mixgtk_cmd_dispatcher.c (limited to 'mixgtk/mixgtk_cmd_dispatcher.c') diff --git a/mixgtk/mixgtk_cmd_dispatcher.c b/mixgtk/mixgtk_cmd_dispatcher.c new file mode 100644 index 0000000..c5fef58 --- /dev/null +++ b/mixgtk/mixgtk_cmd_dispatcher.c @@ -0,0 +1,117 @@ +/* -*-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" + * ------------------------------------------------------------------ + * 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_cmd_dispatcher.h" + +/* a mix vm command dispatcher */ +struct mixgtk_dispatch_ +{ + mix_vm_cmd_dispatcher_t *dispatcher; + FILE *out; + char *out_buffer; + size_t out_buffer_size; + GtkWidget *prompt; + GtkWidget *log; +}; + +static struct mixgtk_dispatch_ dis_data_ = {NULL}; + +/* global hooks for the command dispatcher */ +static void +global_pre_hook_ (mix_vm_cmd_dispatcher_t *dis, + mix_vm_command_t cmd, const gchar *arg, gpointer data) +{ + if (cmd < MIX_CMD_INVALID) + { + gtk_text_insert (GTK_TEXT (dis_data_.log), NULL, NULL, NULL, + "MIX> ", -1); + gtk_text_insert (GTK_TEXT (dis_data_.log), NULL, NULL, NULL, + mix_vm_command_to_string (cmd), -1); + gtk_text_insert (GTK_TEXT (dis_data_.log), NULL, NULL, NULL, + " ", -1); + gtk_text_insert (GTK_TEXT (dis_data_.log), NULL, NULL, NULL, + arg, -1); + gtk_text_insert (GTK_TEXT (dis_data_.log), NULL, NULL, NULL, + "\n", -1); + } + else + { + gtk_text_insert (GTK_TEXT (dis_data_.log), NULL, NULL, NULL, + _("*** Invalid command\n"), -1); + } +} + +static void +global_post_hook_ (mix_vm_cmd_dispatcher_t *dis, + mix_vm_command_t cmd, const gchar *arg, gpointer data) +{ + fflush (dis_data_.out); + if (cmd < MIX_CMD_INVALID) + { + gtk_text_insert (GTK_TEXT (dis_data_.log), NULL, NULL, NULL, + dis_data_.out_buffer, dis_data_.out_buffer_size); + } + rewind (dis_data_.out); +} + + +/* initialise the command dispatcher */ +gboolean +mixgtk_cmd_dispatcher_init (void) +{ + if (!dis_data_.prompt) + { + dis_data_.prompt = mixgtk_widget_factory_get (MIXGTK_WIDGET_PROMPT); + if (!dis_data_.prompt) return FALSE; + dis_data_.log = mixgtk_widget_factory_get (MIXGTK_WIDGET_LOG); + if (!dis_data_.log) return FALSE; + } + + if (!dis_data_.dispatcher) + { + FILE *out = open_memstream (&(dis_data_.out_buffer), + &(dis_data_.out_buffer_size)); + 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); + } + return TRUE; +} + +/* process new command */ +void +on_mixvm_cmd_entry_activate (GtkWidget *w, gpointer e) +{ + gchar *text; + text = gtk_entry_get_text (GTK_ENTRY (w)); + mix_vm_cmd_dispatcher_dispatch_text (dis_data_.dispatcher, text); + gtk_entry_set_text (GTK_ENTRY (w), ""); +} -- cgit v1.2.3