00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "t_wxext_frame.h"
00017
00018 #include <basis/byte_array.h>
00019 #include <basis/istring.h>
00020 #include <basis/portable.h>
00021 #include <opsystem/byte_filer.h>
00022 #include <opsystem/filename.h>
00023 #include <wx_ext/wx_debugging_console_panel.h>
00024
00025 #include <wx/filedlg.h>
00026 #include <wx/fontdlg.h>
00027 #include <wx/menu.h>
00028 #include <wx/msgdlg.h>
00029
00031
00032 BEGIN_EVENT_TABLE(t_wxext_frame, wx_tiny_shell)
00033 EVT_MENU(t_wxext_frame::About, t_wxext_frame::OnAbout)
00034 EVT_MENU(t_wxext_frame::LOAD_FILE_ITEM, t_wxext_frame::OnLoadFile)
00035 EVT_MENU(t_wxext_frame::PICK_FONT_ITEM, t_wxext_frame::OnPickFont)
00036 END_EVENT_TABLE()
00037
00039
00040 t_wxext_frame::t_wxext_frame(const istring &window_title, const istring &root,
00041 int file_size)
00042 : wx_tiny_shell(window_title, root, file_size),
00043 _location(new istring)
00044 {
00045 #if wxUSE_MENUS
00046
00047 wxMenu *opt_menu = new wxMenu;
00048 opt_menu->Append(LOAD_FILE_ITEM, to_unicode_wx("&Load File...\tF2"), to_unicode_wx("Load a File into the buffer"));
00049 opt_menu->Append(PICK_FONT_ITEM, to_unicode_wx("&Pick Font...\tF3"), to_unicode_wx("Pick a font for displaying text"));
00050 GetMenuBar()->Append(opt_menu, to_unicode_wx("&Options"));
00051
00052
00053 wxMenu *helpMenu = new wxMenu;
00054 helpMenu->Append(t_wxext_frame::About, to_unicode_wx("&About...\tF1"), to_unicode_wx("Show about dialog"));
00055
00056
00057 GetMenuBar()->Append(helpMenu, to_unicode_wx("&Help"));
00058 #endif // wxUSE_MENUS
00059
00060 log("Welcome to t_wxext!");
00061 log("This simple application shows how to use the wx_ext library.");
00062 log("It implements a basic logging window.");
00063 }
00064
00065 t_wxext_frame::~t_wxext_frame()
00066 {
00067 WHACK(_location);
00068 }
00069
00070 void t_wxext_frame::OnPickFont(wxCommandEvent &formal(event))
00071 {
00072 wxFontData data;
00073 data.SetInitialFont(GetFont());
00075
00076 wxFontDialog dialog(this, data);
00077 if (dialog.ShowModal() == wxID_OK) {
00078 wxFontData retData = dialog.GetFontData();
00079 wxFont font = retData.GetChosenFont();
00081
00082 panel().get_editor().SetFont(font);
00083 }
00084 }
00085
00086 void t_wxext_frame::OnAbout(wxCommandEvent &WXUNUSED(event))
00087 {
00088 log("About to launch a simple message box as an about dialog.");
00089 wxString msg;
00090 msg.Printf(to_unicode_wx("This is the About dialog of the t_wxext "
00091 "test program.\nWelcome to %s"), wxVERSION_STRING);
00092 wxMessageBox(msg, to_unicode_wx("About t_wxext"), wxOK
00093 | wxICON_INFORMATION, this);
00094 log("Completed OnAbout");
00095 }
00096
00097 void t_wxext_frame::OnLoadFile(wxCommandEvent &WXUNUSED(event))
00098 {
00099 istring default_name = "";
00100 istring file_pattern = "*";
00101 wxFileDialog pick_files(this, to_unicode_wx("Pick a file to display..."),
00102 to_unicode_wx(*_location), to_unicode_wx(default_name),
00103 to_unicode_wx(file_pattern), wxOPEN);
00104 if (pick_files.ShowModal() == wxID_OK) {
00105 istring path = from_unicode_wx(pick_files.GetPath());
00106 filename path_split = path;
00107
00108 *_location = path_split.dirname();
00109
00110 byte_filer chosen_file(path, "rb");
00111 int len = int(chosen_file.length());
00112 byte_array total_content(len + 1);
00113 len = chosen_file.read(total_content, len);
00114 if (len > 0) {
00115 total_content.zap(0, len);
00116 log("here's your file:");
00117 log((const char *)total_content.observe());
00118 log("file contents printed.");
00119 }
00120 }
00121 }
00122