wxgui.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_WXGUI_H
00023 #define MECHSYS_WXGUI_H
00024 
00025 #include <iostream>
00026 #include "wx/wx.h"
00027 
00028 #include "gui/wxgout.h"
00029 
00030 // ------------------------------------- wxApp ------------------------------------
00031 
00032 class App : public wxApp
00033 {
00034 public:
00035     virtual bool OnInit();
00036 }; // class App
00037 
00038 // ------------------------------------ wxFrame -----------------------------------
00039 
00040 class Frame : public wxFrame
00041 {
00042 public:
00043     // Constructor & Destructor
00044     Frame(wxString const & Title);
00045     ~Frame();
00046     // Events
00047     void OnQuit  (wxCommandEvent & Event);
00048     void OnAbout (wxCommandEvent & Event);
00049     void OnRun   (wxCommandEvent & Event);
00050 private:
00051     // Event table
00052     DECLARE_EVENT_TABLE()
00053     // Controls
00054     wxTextCtrl * _term;
00055 }; // class Frame
00056 
00057 
00059 
00060 
00061 // ------------------------------------- wxApp ------------------------------------
00062 
00063 inline bool App::OnInit() // {{{
00064 {
00065     Frame * frame = new Frame(_("Minimal wxWidgets GUI App"));
00066     frame->Show(true);
00067     return true;
00068 } // }}}
00069 
00070 DECLARE_APP (App) // Implements App & GetApp()
00071 
00072 
00073 // ------------------------------------ wxFrame -----------------------------------
00074 
00075 enum // {{{
00076 {
00077     ID_RUN    = 100,
00078 }; // }}}
00079 
00080 inline Frame::Frame(wxString const & Title) // {{{
00081     : wxFrame(/* parent */ NULL, wxID_ANY, Title)
00082 {
00083     // Menubar
00084     wxMenuBar * mnu_bar  = new wxMenuBar;
00085     wxMenu    * mnu_file = new wxMenu;
00086     wxMenu    * mnu_run  = new wxMenu;
00087     wxMenu    * mnu_help = new wxMenu;
00088     mnu_file->Append(wxID_EXIT , _("&Quit\tCtrl-Q")         , _("Quit this program"));
00089     mnu_run ->Append(ID_RUN    , _("&Run\tCtrl-R")          , _("Run simulation"));
00090     mnu_help->Append(wxID_ABOUT, _("&About\tF1")            , _("Show about dialog"));
00091     mnu_bar ->Append(mnu_file  , _("&File"));
00092     mnu_bar ->Append(mnu_run   , _("&Run"));
00093     mnu_bar ->Append(mnu_help  , _("&Help"));
00094     SetMenuBar(mnu_bar);
00095 
00096     // Statusbar
00097     CreateStatusBar(2);
00098     SetStatusText(_("Welcome !"));
00099 
00100     // Text control (Terminal)
00101     _term = new wxTextCtrl(this, wxID_ANY, _("\n"), wxPoint(0,0), wxSize(0,0), wxTE_MULTILINE);
00102     _term->SetBackgroundColour(wxT("wheat"));
00103 } // }}}
00104 
00105 inline Frame::~Frame() // {{{
00106 {
00107 } // }}}
00108 
00109 inline void Frame::OnQuit(wxCommandEvent & Event) // {{{
00110 {
00111     Close();
00112 } // }}}
00113 
00114 inline void Frame::OnAbout(wxCommandEvent & Event) // {{{
00115 {
00116     wxString msg;
00117     msg.Printf(_("Hello and welcome to %s"), wxVERSION_STRING);
00118     wxMessageBox(msg, _("About Minimal"), wxOK | wxICON_INFORMATION, this);
00119 } // }}}
00120 
00121 inline void Frame::OnRun(wxCommandEvent & Event) // {{{
00122 {
00123     Gout   gout(_term);
00124     WGout wgout(_term);
00125     std::basic_streambuf<char> *  cout_sbuf = std::cout.rdbuf(&gout);
00126     std::cout << "cout << Hi from OnRun\n";
00127     std::cout.rdbuf( cout_sbuf);
00128 #ifndef __WXMSW__
00129     std::basic_streambuf<wchar_t> * wcout_sbuf = std::wcout.rdbuf(&wgout);
00130     std::wcout << "wcout << Hi from OnRun\n";
00131     std::wcout.rdbuf(wcout_sbuf);
00132 #endif
00133 } // }}}
00134 
00135 BEGIN_EVENT_TABLE(Frame, wxFrame) // {{{
00136     EVT_MENU (wxID_EXIT , Frame::OnQuit )
00137     EVT_MENU (wxID_ABOUT, Frame::OnAbout)
00138     EVT_MENU (ID_RUN    , Frame::OnRun  )
00139 END_EVENT_TABLE() // }}}
00140 
00141 #endif // MECHSYS_WXGUI_H
00142 
00143 // vim:fdm=marker

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