]>
git.saurik.com Git - wxWidgets.git/blob - samples/html/test/test.cpp
a7130fcb7965383f688580cb1773a57e3e8a57f0
   1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxHtml testing example 
   4 ///////////////////////////////////////////////////////////////////////////// 
   7     #pragma implementation "test.cpp" 
   8     #pragma interface "test.cpp" 
  11 // For compilers that support precompilation, includes "wx/wx.h". 
  12 #include <wx/wxprec.h> 
  18 // for all others, include the necessary headers (this file is usually all you 
  19 // need because it includes almost all "standard" wxWindows headers 
  25 #include <wx/html/htmlwin.h> 
  26 #include <wx/fs_inet.h> 
  28 // ---------------------------------------------------------------------------- 
  30 // ---------------------------------------------------------------------------- 
  32 // Define a new application type, each program should derive a class from wxApp 
  33    class MyApp 
: public wxApp
 
  36     // override base class virtuals 
  37     // ---------------------------- 
  39     // this one is called on application startup and is a good place for the app 
  40     // initialization (doing it here and not in the ctor allows to have an error 
  41     // return: if OnInit() returns false, the application terminates) 
  42       virtual bool OnInit(); 
  45 // Define a new frame type: this is going to be our main frame 
  46    class MyFrame 
: public wxFrame
 
  50       MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
); 
  52     // event handlers (these functions should _not_ be virtual) 
  53       void OnQuit(wxCommandEvent
& event
); 
  54       void OnPageOpen(wxCommandEvent
& event
); 
  55       void OnBack(wxCommandEvent
& event
); 
  56       void OnForward(wxCommandEvent
& event
); 
  60     // any class wishing to process wxWindows events must use this macro 
  64 // ---------------------------------------------------------------------------- 
  66 // ---------------------------------------------------------------------------- 
  68 // IDs for the controls and the menu commands 
  77     // controls start here (the numbers are, of course, arbitrary) 
  81 // ---------------------------------------------------------------------------- 
  82 // event tables and other macros for wxWindows 
  83 // ---------------------------------------------------------------------------- 
  85 // the event tables connect the wxWindows events with the functions (event 
  86 // handlers) which process them. It can be also done at run-time, but for the 
  87 // simple menu events like this the static method is much simpler. 
  88    BEGIN_EVENT_TABLE(MyFrame
, wxFrame
) 
  89    EVT_MENU(Minimal_Quit
,  MyFrame::OnQuit
) 
  90    EVT_MENU(Minimal_PageOpen
, MyFrame::OnPageOpen
) 
  91    EVT_MENU(Minimal_Back
, MyFrame::OnBack
) 
  92    EVT_MENU(Minimal_Forward
, MyFrame::OnForward
) 
  95    // Create a new application object: this macro will allow wxWindows to create 
  96    // the application object during program execution (it's better than using a 
  97    // static object for many reasons) and also declares the accessor function 
  98    // wxGetApp() which will return the reference of the right type (i.e. MyApp and 
 102    // ============================================================================ 
 104    // ============================================================================ 
 106    // ---------------------------------------------------------------------------- 
 107    // the application class 
 108    // ---------------------------------------------------------------------------- 
 109    // `Main program' equivalent: the program execution "starts" here 
 112      wxInitAllImageHandlers(); 
 113      #if wxUSE_FS_INET && wxUSE_STREAMS && wxUSE_SOCKETS 
 114      wxFileSystem::AddHandler(new wxInternetFSHandler
); 
 117       SetVendorName("wxWindows"); 
 118       SetAppName("wxHtmlTest");  
 119       // the following call to wxConfig::Get will use it to create an object... 
 121     // Create the main application window 
 122       MyFrame 
*frame 
= new MyFrame("wxHtmlWindow testing application", 
 123          wxPoint(50, 50), wxSize(640, 480)); 
 125     // Show it and tell the application that it's our main window 
 126     // @@@ what does it do exactly, in fact? is it necessary here? 
 131     // success: wxApp::OnRun() will be called which will enter the main message 
 132     // loop and the application will run. If we returned FALSE here, the 
 133     // application would exit immediately. 
 137 // ---------------------------------------------------------------------------- 
 139 // ---------------------------------------------------------------------------- 
 143    MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
) 
 144    : wxFrame((wxFrame 
*)NULL
, -1, title
, pos
, size
, wxDEFAULT_FRAME_STYLE
, "html_test_app") 
 147       wxMenu 
*menuFile 
= new wxMenu
; 
 148       wxMenu 
*menuNav 
= new wxMenu
; 
 150       menuFile
->Append(Minimal_PageOpen
, "&Open HTML page..."); 
 151       menuFile
->AppendSeparator(); 
 152       menuFile
->Append(Minimal_Quit
, "&Close frame"); 
 153       menuNav
->Append(Minimal_Back
, "Go &BACK"); 
 154       menuNav
->Append(Minimal_Forward
, "Go &FORWARD"); 
 156     // now append the freshly created menu to the menu bar... 
 157       wxMenuBar 
*menuBar 
= new wxMenuBar
; 
 158       menuBar
->Append(menuFile
, "&File"); 
 159       menuBar
->Append(menuNav
, "&Navigate"); 
 161     // ... and attach this menu bar to the frame 
 166       m_Html 
= new wxHtmlWindow(this); 
 167       m_Html 
-> SetRelatedFrame(this, "HTML : %s"); 
 168       m_Html 
-> SetRelatedStatusBar(0); 
 169       m_Html 
-> ReadCustomization(wxConfig::Get()); 
 170       m_Html 
-> LoadPage("test.htm"); 
 176    void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
)) 
 178     // TRUE is to force the frame to close 
 179     m_Html 
-> WriteCustomization(wxConfig::Get()); 
 180     delete wxConfig::Set(NULL
); 
 184    void MyFrame::OnPageOpen(wxCommandEvent
& WXUNUSED(event
)) 
 186      wxString p 
= wxFileSelector("Open HTML document", "", "", "", "HTML files|*.htm"); 
 187      if (p 
!= wxEmptyString
) 
 188        m_Html 
-> LoadPage(p
); 
 193    void MyFrame::OnBack(wxCommandEvent
& WXUNUSED(event
)) 
 195    if (!m_Html 
-> HistoryBack()) wxMessageBox("You reached prehistory era!"); 
 199    void MyFrame::OnForward(wxCommandEvent
& WXUNUSED(event
)) 
 201    if (!m_Html 
-> HistoryForward()) wxMessageBox("No more items in history!");