2006-01-27 18:57:53 +01:00
|
|
|
// src/graphicalterminalio.cc - Copyright 2005, 2006, University
|
2006-01-27 16:04:06 +01:00
|
|
|
// of Padova, dept. of Pure and Applied
|
|
|
|
// Mathematics
|
|
|
|
//
|
|
|
|
// This file is part of SGPEMv2.
|
|
|
|
//
|
|
|
|
// This 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.
|
|
|
|
//
|
|
|
|
// SGPEMv2 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 SGPEMv2; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
|
2006-02-09 20:43:24 +01:00
|
|
|
#include "graphical_terminal_io.hh"
|
2006-01-27 16:04:06 +01:00
|
|
|
|
2006-02-22 23:45:06 +01:00
|
|
|
#include <glibmm/thread.h>
|
2006-01-27 16:04:06 +01:00
|
|
|
#include <gtkmm/button.h>
|
|
|
|
#include <gtkmm/textview.h>
|
|
|
|
#include <glibmm/ustring.h>
|
|
|
|
|
2006-02-10 21:44:48 +01:00
|
|
|
#include <algorithm>
|
2006-02-22 23:45:06 +01:00
|
|
|
#include <utility>
|
2006-02-10 21:44:48 +01:00
|
|
|
|
2006-02-09 20:33:35 +01:00
|
|
|
using namespace sgpem;
|
2006-02-22 23:45:06 +01:00
|
|
|
using namespace std;
|
|
|
|
using Glib::ustring;
|
|
|
|
using Glib::Thread;
|
2006-01-27 16:04:06 +01:00
|
|
|
|
2006-02-22 23:45:06 +01:00
|
|
|
GraphicalTerminalIO::GraphicalTerminalIO(TextSimulation* sim)
|
|
|
|
:_sim(sim)
|
2006-02-10 21:44:48 +01:00
|
|
|
{
|
|
|
|
using namespace Gtk;
|
|
|
|
|
|
|
|
set_title(_("Textual Simulation Log"));
|
|
|
|
set_default_size(500,300);
|
|
|
|
|
|
|
|
Gtk::Box* mainbox = manage(new VBox());
|
|
|
|
add(*mainbox);
|
|
|
|
|
|
|
|
_text_output.set_editable(false);
|
|
|
|
_text_output.modify_font(Pango::FontDescription("monospace"));
|
|
|
|
mainbox->pack_start(_text_output);
|
|
|
|
|
|
|
|
Gtk::Box* cmdbox = manage(new HBox());
|
|
|
|
mainbox->pack_end(*cmdbox, false, false);
|
|
|
|
|
|
|
|
cmdbox->pack_start(_text_input);
|
|
|
|
|
2006-02-22 23:45:06 +01:00
|
|
|
_send = manage(new Button(_("Send Command")));
|
|
|
|
_send->signal_clicked().connect(sigc::mem_fun(*this, &sgpem::GraphicalTerminalIO::onSend));
|
|
|
|
cmdbox->pack_start(*_send, false, true);
|
2006-02-10 21:44:48 +01:00
|
|
|
|
2006-02-22 23:45:06 +01:00
|
|
|
_text_input.grab_focus();
|
|
|
|
|
|
|
|
//this button is the default widget
|
|
|
|
//GTK_WIDGET_SET_FLAGS ( _send , GTK_CAN_DEFAULT);
|
|
|
|
//_send->grab_default();
|
|
|
|
|
2006-02-10 21:44:48 +01:00
|
|
|
show_all_children();
|
|
|
|
}
|
2006-01-27 16:04:06 +01:00
|
|
|
|
|
|
|
GraphicalTerminalIO::~GraphicalTerminalIO()
|
2006-02-09 20:33:35 +01:00
|
|
|
{}
|
2006-01-27 16:04:06 +01:00
|
|
|
|
2006-02-22 23:45:06 +01:00
|
|
|
void
|
|
|
|
GraphicalTerminalIO::onSend()
|
|
|
|
{
|
|
|
|
|
|
|
|
pair< pair<TextSimulation*, IOManager*>, const ustring > p(
|
|
|
|
pair<TextSimulation*, IOManager*>(_sim, this), _text_input.get_text());
|
|
|
|
|
|
|
|
Thread::create( sigc::bind(&TextSimulation::parse_command, p), true);
|
|
|
|
|
|
|
|
_text_input.set_text("");
|
|
|
|
_text_input.grab_focus();
|
|
|
|
}
|
|
|
|
|
2006-02-15 23:58:18 +01:00
|
|
|
uint
|
2006-01-27 16:04:06 +01:00
|
|
|
GraphicalTerminalIO::write_buffer(const Glib::ustring& buffer)
|
|
|
|
{
|
2006-02-22 23:45:06 +01:00
|
|
|
Gtk::TextBuffer::iterator i = _text_output.get_buffer()->end();
|
2006-02-23 13:12:43 +01:00
|
|
|
_text_output.get_buffer()->insert(i, buffer);
|
2006-02-22 23:45:06 +01:00
|
|
|
i = _text_output.get_buffer()->end();
|
2006-02-23 13:12:43 +01:00
|
|
|
//_text_output.scroll_to(i); // would need a mutex!
|
2006-02-22 23:45:06 +01:00
|
|
|
return buffer.size();
|
2006-01-27 16:04:06 +01:00
|
|
|
}
|
|
|
|
|
2006-02-10 21:44:48 +01:00
|
|
|
Glib::ustring
|
2006-02-15 23:58:18 +01:00
|
|
|
GraphicalTerminalIO::read_command()
|
2006-01-27 16:04:06 +01:00
|
|
|
{
|
2006-02-10 21:44:48 +01:00
|
|
|
using Glib::ustring;
|
|
|
|
static const ustring whitespaces = " \r\b\n\t\a";
|
|
|
|
// are there any other wspaces?
|
|
|
|
|
|
|
|
ustring command = _text_input.get_text();
|
|
|
|
|
|
|
|
// trimming:
|
2006-02-15 23:58:18 +01:00
|
|
|
uint f = command.find_first_not_of(whitespaces);
|
|
|
|
uint l = command.find_last_not_of(whitespaces);
|
2006-02-10 21:44:48 +01:00
|
|
|
if(f == ustring::npos)
|
2006-02-17 23:19:25 +01:00
|
|
|
return "";
|
2006-02-10 21:44:48 +01:00
|
|
|
|
2006-02-17 23:19:25 +01:00
|
|
|
return command.substr(f,l-f+1);
|
2006-01-27 16:04:06 +01:00
|
|
|
}
|
2006-02-17 23:19:25 +01:00
|
|
|
|
|
|
|
bool
|
|
|
|
GraphicalTerminalIO::is_full_duplex()
|
|
|
|
{
|
|
|
|
return true;
|
2006-02-19 23:36:24 +01:00
|
|
|
}
|