]>
git.saurik.com Git - wxWidgets.git/blob - samples/html/test/test.cpp
ed81723f0ba061f5616020112f0beccd61d66a30
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>
27 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
31 // Define a new application type, each program should derive a class from wxApp
32 class MyApp
: public wxApp
35 // override base class virtuals
36 // ----------------------------
38 // this one is called on application startup and is a good place for the app
39 // initialization (doing it here and not in the ctor allows to have an error
40 // return: if OnInit() returns false, the application terminates)
41 virtual bool OnInit();
44 // Define a new frame type: this is going to be our main frame
45 class MyFrame
: public wxFrame
49 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
51 // event handlers (these functions should _not_ be virtual)
52 void OnQuit(wxCommandEvent
& event
);
53 void OnAbout(wxCommandEvent
& event
);
54 void OnBack(wxCommandEvent
& event
);
55 void OnForward(wxCommandEvent
& event
);
59 // any class wishing to process wxWindows events must use this macro
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 // IDs for the controls and the menu commands
76 // controls start here (the numbers are, of course, arbitrary)
80 // ----------------------------------------------------------------------------
81 // event tables and other macros for wxWindows
82 // ----------------------------------------------------------------------------
84 // the event tables connect the wxWindows events with the functions (event
85 // handlers) which process them. It can be also done at run-time, but for the
86 // simple menu events like this the static method is much simpler.
87 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
88 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
89 EVT_MENU(Minimal_About
, MyFrame::OnAbout
)
90 EVT_MENU(Minimal_Back
, MyFrame::OnBack
)
91 EVT_MENU(Minimal_Forward
, MyFrame::OnForward
)
94 // Create a new application object: this macro will allow wxWindows to create
95 // the application object during program execution (it's better than using a
96 // static object for many reasons) and also declares the accessor function
97 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
101 // ============================================================================
103 // ============================================================================
105 // ----------------------------------------------------------------------------
106 // the application class
107 // ----------------------------------------------------------------------------
108 // `Main program' equivalent: the program execution "starts" here
111 wxLogDebug("[starting testing app]");
113 wxImage::AddHandler(new wxPNGHandler
);
116 wxImage::AddHandler(new wxJPEGHandler
);
119 wxImage::AddHandler(new wxGIFHandler
);
122 wxFileSystem::AddHandler(new wxInternetFSHandler
);
124 // Create the main application window
125 MyFrame
*frame
= new MyFrame("wxHtmlWindow testing application",
126 wxPoint(50, 50), wxSize(640, 480));
127 MyFrame
*frame2
= new MyFrame("wxHtmlWindow testing application, frame 2",
128 wxPoint(150, 50), wxSize(320, 240));
130 // Show it and tell the application that it's our main window
131 // @@@ what does it do exactly, in fact? is it necessary here?
137 // success: wxApp::OnRun() will be called which will enter the main message
138 // loop and the application will run. If we returned FALSE here, the
139 // application would exit immediately.
143 // ----------------------------------------------------------------------------
145 // ----------------------------------------------------------------------------
149 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
150 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
, wxDEFAULT_FRAME_STYLE
, "html_test_app")
153 wxMenu
*menuFile
= new wxMenu
;
154 wxMenu
*menuNav
= new wxMenu
;
156 menuFile
->Append(Minimal_About
, "&Load wxWindows manual page");
157 menuFile
->AppendSeparator();
158 menuFile
->Append(Minimal_Quit
, "&Close frame");
159 menuNav
->Append(Minimal_Back
, "Go &BACK");
160 menuNav
->Append(Minimal_Forward
, "Go &FORWARD");
162 // now append the freshly created menu to the menu bar...
163 wxMenuBar
*menuBar
= new wxMenuBar
;
164 menuBar
->Append(menuFile
, "&File");
165 menuBar
->Append(menuNav
, "&Navigate");
167 // ... and attach this menu bar to the frame
173 wxConfig
*cfg
= new wxConfig("wxHtmlTest");
174 m_Html
= new wxHtmlWindow(this);
175 m_Html
-> SetRelatedFrame(this, "HTML : %s");
176 m_Html
-> SetRelatedStatusBar(0);
177 m_Html
-> ReadCustomization(cfg
);
179 m_Html
-> LoadPage("test.htm");
186 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
188 // TRUE is to force the frame to close
189 wxLogDebug("about to save config...");
190 wxConfig
*cfg
= new wxConfig("wxHtmlTest");
191 m_Html
-> WriteCustomization(cfg
);
196 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
198 m_Html
-> LoadPage("fft.html");
203 void MyFrame::OnBack(wxCommandEvent
& WXUNUSED(event
))
205 if (!m_Html
-> HistoryBack()) wxMessageBox("You reached prehistory era!");
209 void MyFrame::OnForward(wxCommandEvent
& WXUNUSED(event
))
211 if (!m_Html
-> HistoryForward()) wxMessageBox("No more items in history!");