From d6a19ca35d02954351c21161def8b290e95ff22d Mon Sep 17 00:00:00 2001 From: tchernobog Date: Fri, 10 Feb 2006 20:44:48 +0000 Subject: [PATCH] - Write code for the graphical terminal widget git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@315 3ecf2c5c-341e-0410-92b4-d18e462d057c --- src/graphical_terminal_io.cc | 52 +++++++++++++++++++++++++++++++----- src/graphical_terminal_io.hh | 11 ++++---- src/io_manager.hh | 4 +-- src/main.cc | 2 +- src/main_window.cc | 2 +- src/start_gui.cc | 4 +-- 6 files changed, 57 insertions(+), 18 deletions(-) diff --git a/src/graphical_terminal_io.cc b/src/graphical_terminal_io.cc index e32b4b3..5a4255b 100644 --- a/src/graphical_terminal_io.cc +++ b/src/graphical_terminal_io.cc @@ -27,10 +27,36 @@ #include #include +#include + using namespace sgpem; GraphicalTerminalIO::GraphicalTerminalIO() -{} +{ + 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); + + //Gtk::Button* bt_tell = manage(new Button(_("Tell"))); + // signals lack return value: + //bt_tell->signal_clicked().connect(sigc::mem_fun(*this, read_buffer)); + //cmdbox->pack_start(*bt_tell, false, true); + + show_all_children(); +} GraphicalTerminalIO::~GraphicalTerminalIO() {} @@ -38,13 +64,25 @@ GraphicalTerminalIO::~GraphicalTerminalIO() GraphicalTerminalIO::size_type GraphicalTerminalIO::write_buffer(const Glib::ustring& buffer) { - // FIXME - return 0; + _text_output.get_buffer()->insert_at_cursor(buffer); + return buffer.size(); } -GraphicalTerminalIO::size_type -GraphicalTerminalIO::read_command(Glib::ustring& buffer) const +Glib::ustring +GraphicalTerminalIO::read_command() const { - // FIXME - return 0; + using Glib::ustring; + static const ustring whitespaces = " \r\b\n\t\a"; + // are there any other wspaces? + + ustring command = _text_input.get_text(); + + // trimming: + size_type f = command.find_first_not_of(whitespaces); + size_type l = command.find_last_not_of(whitespaces); + if(f == ustring::npos) + return 0; + + _text_input.set_text(ustring("")); + return command.substr(f,l); } diff --git a/src/graphical_terminal_io.hh b/src/graphical_terminal_io.hh index c3fe16c..3d48e52 100644 --- a/src/graphical_terminal_io.hh +++ b/src/graphical_terminal_io.hh @@ -27,6 +27,7 @@ #include #include #include +#include #include #include "io_manager.hh" @@ -42,18 +43,18 @@ namespace sgpem { /** \brief * * ... long desc ... */ - class GraphicalTerminalIO : public IOManager, public Gtk::VBox + class GraphicalTerminalIO : public IOManager, public Gtk::Window { typedef unsigned int size_type; public: GraphicalTerminalIO(); virtual ~GraphicalTerminalIO(); - virtual size_type write_buffer(const Glib::ustring& buffer); - virtual size_type read_command(Glib::ustring& buffer) const; + virtual size_type write_buffer(const Glib::ustring& buffer); + virtual Glib::ustring read_command() const; private: - Gtk::TextView text_output; - Gtk::Entry text_input; + Gtk::TextView _text_output; + mutable Gtk::Entry _text_input; }; } diff --git a/src/io_manager.hh b/src/io_manager.hh index e765cd5..3fdb21b 100644 --- a/src/io_manager.hh +++ b/src/io_manager.hh @@ -43,8 +43,8 @@ namespace sgpem { public: virtual ~IOManager() {} - virtual size_type write_buffer(const Glib::ustring& buffer) = 0; - virtual size_type read_command(Glib::ustring& buffer) const = 0; + virtual size_type write_buffer(const Glib::ustring& buffer) = 0; + virtual Glib::ustring read_command() const = 0; }; } diff --git a/src/main.cc b/src/main.cc index dcc248f..a788727 100644 --- a/src/main.cc +++ b/src/main.cc @@ -61,7 +61,7 @@ main(int argc, char* argv[]) filenames.insert(filenames.begin(), a_ptr, a_ptr+a_count); } */ - //start_gui(argc, argv); + start_gui(argc, argv); //SMOKE-TEST for backend classes cout << "\n\n********************************"; diff --git a/src/main_window.cc b/src/main_window.cc index 6a10372..2127f33 100644 --- a/src/main_window.cc +++ b/src/main_window.cc @@ -34,7 +34,7 @@ using namespace sgpem; MainWindow::MainWindow() { set_title(PACKAGE_STRING); - set_default_size(800, 600); + //set_default_size(800, 600); Gtk::Box* mainbox = manage(new Gtk::VBox()); add(*mainbox); diff --git a/src/start_gui.cc b/src/start_gui.cc index 7f63642..9d4d8bb 100644 --- a/src/start_gui.cc +++ b/src/start_gui.cc @@ -21,7 +21,7 @@ #include "config.h" #include "gettext.h" -#include "main_window.hh" +#include "graphical_terminal_io.hh" #include "start_gui.hh" #include @@ -30,6 +30,6 @@ void start_gui(int argc, char** argv) { Gtk::Main gtk_main(argc,argv); - sgpem::MainWindow main_window; + sgpem::GraphicalTerminalIO main_window; Gtk::Main::run(main_window); }