t_wxext_frame.cpp

Go to the documentation of this file.
00001 /*****************************************************************************\
00002 *                                                                             *
00003 *  Name   : t_wxext_frame                                                     *
00004 *  Author : Chris Koeritz                                                     *
00005 *  Author : Aaron Buchanan                                                    *
00006 *                                                                             *
00007 *******************************************************************************
00008 * Copyright (c) 1995-$now By Author.  This program is free software; you can  *
00009 * redistribute it and/or modify it under the terms of the GNU General Public  *
00010 * License as published by the Free Software Foundation; either version 2 of   *
00011 * the License or (at your option) any later version.  This is online at:      *
00012 *     http://www.fsf.org/copyleft/gpl.html                                    *
00013 * Please send any updates to: fred@gruntose.com                               *
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   // add a menu for loading a file into the buffer.
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   // the "About" item should be in the help menu
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   // now append the freshly created menu to the menu bar...
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     // save the location where they browsed last.
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 

Generated on Fri Nov 21 04:30:04 2008 for HOOPLE Libraries by  doxygen 1.5.1