trealinp-gui.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 #include "wx/grid.h"
00028 
00029 #include "gui/wxrealnuminput.h"
00030 
00031 // ------------------------------------- wxApp ------------------------------------
00032 
00033 class App : public wxApp
00034 {
00035 public:
00036     virtual bool OnInit();
00037 }; // class App
00038 
00039 // ------------------------------------ wxFrame -----------------------------------
00040 
00041 class Frame : public wxFrame
00042 {
00043 public:
00044     // Constructor & Destructor
00045     Frame(wxString const & Title);
00046     ~Frame();
00047     // Events
00048     void OnQuit        (wxCommandEvent       & Event);
00049     void OnAbout       (wxCommandEvent       & Event);
00050     void OnInp1Changed (WxRealNumInput_Event & Event);
00051     void OnInp2Changed (WxRealNumInput_Event & Event);
00052     void OnInp3Changed (WxRealNumInput_Event & Event);
00053 private:
00054     // Event table
00055     DECLARE_EVENT_TABLE()
00056     // Controls
00057     WxRealNumInput * _inp_1;
00058     WxRealNumInput * _inp_2;
00059     WxRealNumInput * _inp_3;
00060 }; // class Frame
00061 
00062 
00064 
00065 
00066 // ------------------------------------- wxApp ------------------------------------
00067 
00068 inline bool App::OnInit() // {{{
00069 {
00070     Frame * frame = new Frame(_("Minimal wxWidgets GUI App"));
00071     frame->Show(true);
00072     return true;
00073 } // }}}
00074 
00075 DECLARE_APP (App) // Implements App & GetApp()
00076 
00077 
00078 // ------------------------------------ wxFrame -----------------------------------
00079 
00080 enum // {{{
00081 {
00082     ID_RUN   = 100,
00083     ID_INP_1 = 110,
00084     ID_INP_2 = 120,
00085     ID_INP_3 = 130
00086 }; // }}}
00087 
00088 inline Frame::Frame(wxString const & Title) // {{{
00089     : wxFrame(/* parent */ NULL, wxID_ANY, Title)
00090 {
00091     // Menubar
00092     wxMenuBar * mnu_bar  = new wxMenuBar;
00093     wxMenu    * mnu_file = new wxMenu;
00094     wxMenu    * mnu_run  = new wxMenu;
00095     wxMenu    * mnu_help = new wxMenu;
00096     mnu_file->Append(wxID_EXIT , _("&Quit\tCtrl-Q")         , _("Quit this program"));
00097     mnu_run ->Append(ID_RUN    , _("&Run\tCtrl-R")          , _("Run simulation"));
00098     mnu_help->Append(wxID_ABOUT, _("&About\tF1")            , _("Show about dialog"));
00099     mnu_bar ->Append(mnu_file  , _("&File"));
00100     mnu_bar ->Append(mnu_run   , _("&Run"));
00101     mnu_bar ->Append(mnu_help  , _("&Help"));
00102     SetMenuBar(mnu_bar);
00103 
00104     // Statusbar
00105     CreateStatusBar(2);
00106     SetStatusText(_("Welcome !"));
00107 
00108     // Real number input
00109     _inp_1 = new WxRealNumInput(this, ID_INP_1, _T("123.456"), wxDefaultPosition, wxDefaultSize);
00110     _inp_2 = new WxRealNumInput(this, ID_INP_2, _T("223.456"), wxDefaultPosition, wxDefaultSize);
00111     _inp_3 = new WxRealNumInput(this, ID_INP_3, _T("323.456"), wxDefaultPosition, wxDefaultSize);
00112 
00113     // Sizers
00114     wxBoxSizer * bsz0 = new wxBoxSizer (wxVERTICAL);
00115     bsz0 -> Add          (_inp_1, 0, wxALIGN_LEFT|wxALL, 5);
00116     bsz0 -> Add          (_inp_2, 0, wxALIGN_LEFT|wxALL, 5);
00117     bsz0 -> Add          (_inp_3, 0, wxALIGN_LEFT|wxALL, 5);
00118     this -> SetSizer     (bsz0);
00119     bsz0 -> Fit          (this);
00120     bsz0 -> SetSizeHints (this);
00121 
00122 } // }}}
00123 
00124 inline Frame::~Frame() // {{{
00125 {
00126 } // }}}
00127 
00128 inline void Frame::OnQuit(wxCommandEvent & Event) // {{{
00129 {
00130     Close();
00131 } // }}}
00132 
00133 inline void Frame::OnAbout(wxCommandEvent & Event) // {{{
00134 {
00135     wxString msg;
00136     msg.Printf(_("Hello and welcome to %s"), wxVERSION_STRING);
00137     wxMessageBox(msg, _("About Minimal"), wxOK | wxICON_INFORMATION, this);
00138 } // }}}
00139 
00140 inline void Frame::OnInp1Changed(WxRealNumInput_Event & Event) // {{{
00141 {
00142     wxString msg;
00143     msg.Printf(_("Got number %f"), Event.GetValue());
00144     wxMessageBox(msg, _("OnInp1Changed"), wxOK | wxICON_INFORMATION, this);
00145 } // }}}
00146 
00147 inline void Frame::OnInp2Changed(WxRealNumInput_Event & Event) // {{{
00148 {
00149     wxString msg;
00150     msg.Printf(_("Got number %f"), Event.GetValue());
00151     wxMessageBox(msg, _("OnInp2Changed"), wxOK | wxICON_INFORMATION, this);
00152 } // }}}
00153 
00154 inline void Frame::OnInp3Changed(WxRealNumInput_Event & Event) // {{{
00155 {
00156     wxString msg;
00157     msg.Printf(_("Got number %f"), Event.GetValue());
00158     wxMessageBox(msg, _("OnInp3Changed"), wxOK | wxICON_INFORMATION, this);
00159 } // }}}
00160 
00161 BEGIN_EVENT_TABLE(Frame, wxFrame) // {{{
00162     EVT_MENU            (wxID_EXIT , Frame::OnQuit       )
00163     EVT_MENU            (wxID_ABOUT, Frame::OnAbout      )
00164     EVT_REALNUM_CHANGED (ID_INP_1  , Frame::OnInp1Changed)
00165     EVT_REALNUM_CHANGED (ID_INP_2  , Frame::OnInp2Changed)
00166     EVT_REALNUM_CHANGED (ID_INP_3  , Frame::OnInp3Changed)
00167 END_EVENT_TABLE() // }}}
00168 
00169 #endif // MECHSYS_WXGUI_H
00170 
00171 // vim:fdm=marker

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