wxgout.h

00001 /*************************************************************************************
00002  * MechSys - A C++ library to simulate (Continuum) Mechanical Systems                *
00003  * Copyright (C) 2005 Dorival de Moraes Pedroso <dorival.pedroso at gmail.com>       *
00004  * Copyright (C) 2005 Raul Dario Durand Farfan  <raul.durand at gmail.com>           *
00005  *                                                                                   *
00006  * This file is part of MechSys.                                                     *
00007  *                                                                                   *
00008  * MechSys is free software; you can redistribute it and/or modify it under the      *
00009  * terms of the GNU General Public License as published by the Free Software         *
00010  * Foundation; either version 2 of the License, or (at your option) any later        *
00011  * version.                                                                          *
00012  *                                                                                   *
00013  * MechSys is distributed in the hope that it will be useful, but WITHOUT ANY        *
00014  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A   *
00015  * PARTICULAR PURPOSE. See the GNU General Public License for more details.          *
00016  *                                                                                   *
00017  * You should have received a copy of the GNU General Public License along with      *
00018  * MechSys; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, *
00019  * Fifth Floor, Boston, MA 02110-1301, USA                                           *
00020  *************************************************************************************/
00021 
00022 #ifndef MECHSYS_WXGOUT_H
00023 #define MECHSYS_WXGOUT_H
00024 
00025 #include <streambuf>
00026 #include <wx/wxchar.h>
00027 #include <wx/textctrl.h>
00028 
00029 class Gout : public std::basic_streambuf<char>
00030 {
00031     typedef std::char_traits<char> traits_type;
00032     typedef traits_type::int_type  int_type;
00033 public:
00034     Gout(wxTextCtrl * TC, bool Threaded=false) : _tc(TC), _threaded(Threaded) {}
00035 protected:
00036     virtual int_type overflow(int_type c=EOF);
00037 private:
00038     wxTextCtrl * _tc;
00039     bool         _threaded;
00040 }; // class Gout
00041 
00042 
00043 class WGout : public std::basic_streambuf<wchar_t>
00044 {
00045     typedef std::char_traits<wchar_t> traits_type;
00046     typedef traits_type::int_type  int_type;
00047 public:
00048     WGout(wxTextCtrl * TC, bool Threaded=false) : _tc(TC), _threaded(Threaded) {}
00049 protected:
00050     virtual int_type overflow(int_type c=EOF);
00051 private:
00052     wxTextCtrl * _tc;
00053     bool         _threaded;
00054 }; // class Gout
00055 
00056 
00057 
00059 
00060 
00061 inline Gout::int_type Gout::overflow(Gout::int_type c) // {{{
00062 {
00063     if (!_tc) return traits_type::eof();
00064     if (!traits_type::eq_int_type(traits_type::eof(), c))
00065     {
00066         if (_threaded) wxMutexGuiEnter(); // <<< THREADED
00067 
00068         wxString txt; txt.Printf(_("%c"),traits_type::to_char_type(c));
00069         _tc->AppendText(txt);
00070 
00071         if (_threaded) wxMutexGuiLeave(); // <<< THREADED
00072     }
00073     return traits_type::not_eof(c);
00074 } // }}}
00075 
00076 inline WGout::int_type WGout::overflow(WGout::int_type c) // {{{
00077 {
00078     if (!_tc) return traits_type::eof();
00079     if (!traits_type::eq_int_type(traits_type::eof(), c))
00080     {
00081         if (_threaded) wxMutexGuiEnter(); // <<< THREADED
00082 
00083         wxString txt(traits_type::to_char_type(c));
00084         _tc->AppendText(txt);
00085 
00086         if (_threaded) wxMutexGuiLeave(); // <<< THREADED
00087     }
00088     return traits_type::not_eof(c);
00089 } // }}}
00090 
00091 #endif // MECHSYS_WXGOUT_H
00092 
00093 // vim:fdm=marker

Generated on Wed Jan 24 15:56:26 2007 for MechSys by  doxygen 1.4.7