00001 #ifndef WX_TINY_SHELL_IMPLEMENTATION_FILE
00002 #define WX_TINY_SHELL_IMPLEMENTATION_FILE
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
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
00075 wxMenu *fileMenu = new wxMenu;
00076
00077 fileMenu->Append(wx_tiny_shell::Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
00078
00079
00080 wxMenuBar *menuBar = new wxMenuBar();
00081 menuBar->Append(fileMenu, _T("&File"));
00082
00083
00084 SetMenuBar(menuBar);
00085 #endif // wxUSE_MENUS
00086
00087 #if wxUSE_STATUSBAR
00088
00089 CreateStatusBar(2);
00090 SetStatusText(_T("Welcome to wxWidgets!"));
00091 #endif // wxUSE_STATUSBAR
00092
00093 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
00094
00095
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,
00101 wxEXPAND |
00102 wxALL,
00103 0 );
00104
00105 #ifndef OMIT_PROGRAM_WIDE_LOGGER
00106
00107 _held_logger = retask_program_wide_logger(&debug());
00108 #endif
00109
00110
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;
00135
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
00143 _held_logger = NIL;
00144 if (ignore) {}
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
00169 Close(true);
00170 }
00171
00172
00173 #endif //WX_TINY_SHELL_IMPLEMENTATION_FILE
00174