wx_tiny_shell.cpp

Go to the documentation of this file.
00001 #ifndef WX_TINY_SHELL_IMPLEMENTATION_FILE
00002 #define WX_TINY_SHELL_IMPLEMENTATION_FILE
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : wx_tiny_shell                                                     *
00007 *  Author : Aaron Buchanan                                                    *
00008 *  Author : Chris Koeritz                                                     *
00009 *                                                                             *
00010 *******************************************************************************
00011 * Copyright (c) 1995-$now By Authors.  This program is free software; you can *
00012 * redistribute it and/or modify it under the terms of the GNU General Public  *
00013 * License as published by the Free Software Foundation; either version 2 of   *
00014 * the License or (at your option) any later version.  This is online at:      *
00015 *     http://www.fsf.org/copyleft/gpl.html                                    *
00016 * Please send any updates to: fred@gruntose.com                               *
00017 \*****************************************************************************/
00018 
00019 #include "wx_debugger.h"
00020 #include "wx_debugging_console_panel.h"
00021 #include "wx_tiny_shell.h"
00022 
00023 #include <basis/convert_utf.h>
00024 #include <geometric/rectangle.cpp>
00025 #include <geometric/screen_rectangle.h>
00026 #include <opsystem/ini_config.h>
00027 #include <opsystem/path_configuration.h>
00028 
00029 #undef GetClassInfo
00030 #include <wx/icon.h>
00031 #include <wx/menu.h>
00032 #include <wx/msgdlg.h>
00033 #include <wx/sizer.h>
00034 
00035 using namespace geometric;
00036 
00037 #define INI_NAME(root) (root + istring(".ini"))
00038 
00039 #define LOG_NAME(root) (path_configuration::make_logfile_name(root + istring(".log")))
00040 
00042 
00043 BEGIN_EVENT_TABLE(wx_tiny_shell, wxFrame)
00044   EVT_COMMAND(wxID_ANY, wx_debugger::EVENT(), wx_tiny_shell::OnDebugEvent)
00045   EVT_CLOSE(wx_tiny_shell::OnCloseWindow)
00046   EVT_MENU(wx_tiny_shell::Quit, wx_tiny_shell::OnQuit)
00047 END_EVENT_TABLE()
00048 
00050 
00051 wx_tiny_shell::wx_tiny_shell(const istring &window_title,
00052     const istring &root, int file_size, const istring &logfile_name)
00053 : wxFrame(NULL, wxID_ANY, to_unicode_wx(window_title)), 
00054   application_shell(root),
00055   _panel(NULL), 
00056   _debug(new wx_debugger(0, debugger::delayed)),
00057   _held_logger(NIL),
00058   _exiting(false),
00059   _logfile_name(new istring(logfile_name))
00060 {
00061   // get the window parameters...
00062   screen_rectangle win_size;
00063   wxRect loc = GetRect();
00064   screen_rectangle default_size(loc.x, loc.y, loc.GetRight(), loc.GetBottom());
00065   istring tmp = ini().load(filename_root(), istring("window_size"), default_size.text_form());
00066   win_size.from_text(tmp);
00067   loc.x = win_size.top_left().x();
00068   loc.y = win_size.top_left().y();
00069   loc.width = win_size.width();
00070   loc.height = win_size.height();
00071   SetSize(loc);
00072 
00073 #if wxUSE_MENUS
00074   // create a menu bar
00075   wxMenu *fileMenu = new wxMenu;
00076 
00077   fileMenu->Append(wx_tiny_shell::Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
00078 
00079   // now append the freshly created menu to the menu bar...
00080   wxMenuBar *menuBar = new wxMenuBar();
00081   menuBar->Append(fileMenu, _T("&File"));
00082 
00083   // ... and attach this menu bar to the frame
00084   SetMenuBar(menuBar);
00085 #endif // wxUSE_MENUS
00086 
00087 #if wxUSE_STATUSBAR
00088   // create a status bar just for fun (by default with 1 pane only)
00089   CreateStatusBar(2);
00090   SetStatusText(_T("Welcome to wxWidgets!"));
00091 #endif // wxUSE_STATUSBAR
00092 
00093   wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
00094 
00095   // create the debugging console.
00096   _panel = new wx_debugging_console_panel(this, file_size);
00097   if (_logfile_name->t()) _panel->name(*_logfile_name);
00098   else _panel->name(LOG_NAME(filename_root()));
00099   _panel->SetSize(loc);
00100   topsizer->Add(_panel, 1,            // make vertically stretchable
00101                 wxEXPAND |    // make horizontally stretchable
00102                 wxALL,        //   and make border all around
00103                 0 );         // set border width to 10
00104 
00105 #ifndef OMIT_PROGRAM_WIDE_LOGGER
00106   // swap out the prior logger to send diagnostics to our window.
00107   _held_logger = retask_program_wide_logger(&debug());
00108 #endif
00109 
00110   // set up debugging window.
00111   _debug->reset_recipient((void *)_panel);
00112 
00113   SetSizer(topsizer);
00114 }
00115 
00116 wx_tiny_shell::~wx_tiny_shell()
00117 {
00118   WHACK(_debug);
00119   WHACK(_panel);
00120   WHACK(_logfile_name);
00121 }
00122 
00123 debugger &wx_tiny_shell::debug() const { return *_debug; }
00124 
00125 wx_debugging_console_panel &wx_tiny_shell::panel() { return *_panel; }
00126 
00127 int wx_tiny_shell::execute() { return 0; }
00128 
00129 void wx_tiny_shell::OnCloseWindow(wxCloseEvent &formal(event))
00130 {  
00131   FUNCDEF("OnCloseWindow");
00132   if (_exiting)
00133     non_continuable_error(class_name(), func, "exiting twice?  already trying to exit.");
00134   _exiting = true;  // set our flag to indicate we're leaving.
00135   // save the window parameters...
00136   wxRect rect = GetRect();
00137   screen_rectangle win_size(rect.x, rect.y, rect.GetRight(), rect.GetBottom());
00138   ini().store(filename_root(), istring("window_size"), win_size.text_form());
00139 
00140 #ifndef OMIT_PROGRAM_WIDE_LOGGER
00141   log_base *ignore = retask_program_wide_logger(_held_logger);
00142     // ignore the returned log_base since it's destroyed elsewhere!
00143   _held_logger = NIL;
00144   if (ignore) {}  // nothing.
00145 #endif
00146   Destroy();
00147 }
00148 
00149 void wx_tiny_shell::OnDebugEvent(wxCommandEvent &event)
00150 {
00151   _panel->display_debug_message(event);
00152 }
00153 
00154 outcome wx_tiny_shell::print(const istring &to_print)
00155 {
00156   if (_exiting) return 0;
00157   return _debug->print(to_print);
00158 }
00159 
00160 outcome wx_tiny_shell::log(const istring &to_print)
00161 {
00162   if (_exiting) return 0;
00163   return _debug->log(to_print);
00164 }
00165 
00166 void wx_tiny_shell::OnQuit(wxCommandEvent& WXUNUSED(event))
00167 {
00168     // true is to force the frame to close
00169     Close(true);
00170 }
00171 
00172 
00173 #endif //WX_TINY_SHELL_IMPLEMENTATION_FILE
00174 

Generated on Wed Nov 19 04:28:43 2008 for HOOPLE Libraries by  doxygen 1.5.1