]>
Commit | Line | Data |
---|---|---|
5526e819 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: test.cpp | |
3 | // Purpose: wxHtml testing example | |
4 | ///////////////////////////////////////////////////////////////////////////// | |
5 | ||
788233da | 6 | #if defined(__GNUG__) && !defined(__APPLE__) |
5526e819 VS |
7 | #pragma implementation "test.cpp" |
8 | #pragma interface "test.cpp" | |
9 | #endif | |
10 | ||
11 | // For compilers that support precompilation, includes "wx/wx.h". | |
92a19c2e | 12 | #include "wx/wxprec.h" |
5526e819 VS |
13 | |
14 | #ifdef __BORLANDC__ | |
15 | #pragma hdrstop | |
16 | #endif | |
17 | ||
18 | // for all others, include the necessary headers (this file is usually all you | |
19 | // need because it includes almost all "standard" wxWindows headers | |
20 | #ifndef WX_PRECOMP | |
67547666 | 21 | #include "wx/wx.h" |
5526e819 VS |
22 | #endif |
23 | ||
67547666 GD |
24 | #include "wx/image.h" |
25 | #include "wx/imagpng.h" | |
26 | #include "wx/wxhtml.h" | |
27 | #include "wx/statline.h" | |
5526e819 VS |
28 | |
29 | // ---------------------------------------------------------------------------- | |
30 | // private classes | |
31 | // ---------------------------------------------------------------------------- | |
32 | ||
33 | ||
34 | // Define a new application type, each program should derive a class from wxApp | |
35 | class MyApp : public wxApp | |
36 | { | |
37 | public: | |
38 | // override base class virtuals | |
39 | // ---------------------------- | |
48e74ff5 | 40 | |
5526e819 VS |
41 | // this one is called on application startup and is a good place for the app |
42 | // initialization (doing it here and not in the ctor allows to have an error | |
43 | // return: if OnInit() returns false, the application terminates) | |
44 | virtual bool OnInit(); | |
45 | }; | |
46 | ||
47 | // Define a new frame type: this is going to be our main frame | |
48 | class MyFrame : public wxFrame | |
49 | { | |
50 | public: | |
51 | // ctor(s) | |
52 | MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); | |
48e74ff5 | 53 | |
5526e819 VS |
54 | // event handlers (these functions should _not_ be virtual) |
55 | void OnQuit(wxCommandEvent& event); | |
56 | void OnAbout(wxCommandEvent& event); | |
57 | ||
58 | private: | |
59 | // any class wishing to process wxWindows events must use this macro | |
60 | DECLARE_EVENT_TABLE() | |
61 | }; | |
62 | ||
63 | // ---------------------------------------------------------------------------- | |
64 | // constants | |
65 | // ---------------------------------------------------------------------------- | |
66 | ||
67 | // IDs for the controls and the menu commands | |
68 | enum | |
69 | { | |
70 | // menu items | |
71 | Minimal_Quit = 1, | |
72 | Minimal_About, | |
73 | Minimal_Back, | |
74 | Minimal_Forward, | |
48e74ff5 | 75 | |
5526e819 | 76 | // controls start here (the numbers are, of course, arbitrary) |
b6fa52db | 77 | Minimal_Text = 1000 |
5526e819 VS |
78 | }; |
79 | ||
80 | // ---------------------------------------------------------------------------- | |
81 | // event tables and other macros for wxWindows | |
82 | // ---------------------------------------------------------------------------- | |
83 | ||
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 | END_EVENT_TABLE() | |
48e74ff5 | 91 | |
5526e819 VS |
92 | // Create a new application object: this macro will allow wxWindows to create |
93 | // the application object during program execution (it's better than using a | |
94 | // static object for many reasons) and also declares the accessor function | |
95 | // wxGetApp() which will return the reference of the right type (i.e. MyApp and | |
96 | // not wxApp) | |
97 | IMPLEMENT_APP(MyApp) | |
48e74ff5 | 98 | |
5526e819 VS |
99 | // ============================================================================ |
100 | // implementation | |
101 | // ============================================================================ | |
48e74ff5 | 102 | |
5526e819 VS |
103 | // ---------------------------------------------------------------------------- |
104 | // the application class | |
105 | // ---------------------------------------------------------------------------- | |
106 | // `Main program' equivalent: the program execution "starts" here | |
107 | bool MyApp::OnInit() | |
108 | { | |
109 | wxImage::AddHandler(new wxPNGHandler); | |
110 | // Create the main application window | |
2b5f62a0 | 111 | MyFrame *frame = new MyFrame(_("wxHtmlWindow testing application"), |
5526e819 | 112 | wxPoint(50, 50), wxSize(150, 50)); |
48e74ff5 | 113 | |
5526e819 VS |
114 | // Show it and tell the application that it's our main window |
115 | // @@@ what does it do exactly, in fact? is it necessary here? | |
348469c2 | 116 | frame->Show(true); |
5526e819 VS |
117 | SetTopWindow(frame); |
118 | ||
119 | ||
120 | // success: wxApp::OnRun() will be called which will enter the main message | |
348469c2 | 121 | // loop and the application will run. If we returned false here, the |
5526e819 | 122 | // application would exit immediately. |
348469c2 | 123 | return true; |
5526e819 VS |
124 | } |
125 | ||
126 | // ---------------------------------------------------------------------------- | |
127 | // main frame | |
128 | // ---------------------------------------------------------------------------- | |
129 | ||
130 | ||
131 | // frame constructor | |
132 | MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) | |
348469c2 | 133 | : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size) |
5526e819 VS |
134 | { |
135 | // create a menu bar | |
136 | wxMenu *menuFile = new wxMenu; | |
137 | ||
2b5f62a0 VZ |
138 | menuFile->Append(Minimal_About, _("&About")); |
139 | menuFile->Append(Minimal_Quit, _("E&xit")); | |
5526e819 VS |
140 | |
141 | // now append the freshly created menu to the menu bar... | |
142 | wxMenuBar *menuBar = new wxMenuBar; | |
2b5f62a0 | 143 | menuBar->Append(menuFile, _("&File")); |
5526e819 VS |
144 | |
145 | // ... and attach this menu bar to the frame | |
146 | SetMenuBar(menuBar); | |
147 | } | |
148 | ||
149 | ||
150 | // event handlers | |
151 | ||
152 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) | |
153 | { | |
348469c2 WS |
154 | // true is to force the frame to close |
155 | Close(true); | |
5526e819 VS |
156 | } |
157 | ||
158 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) | |
159 | { | |
0f91df4f | 160 | wxBoxSizer *topsizer; |
5526e819 | 161 | wxHtmlWindow *html; |
348469c2 | 162 | wxDialog dlg(this, wxID_ANY, wxString(_("About"))); |
0f91df4f VS |
163 | |
164 | topsizer = new wxBoxSizer(wxVERTICAL); | |
5526e819 | 165 | |
348469c2 | 166 | html = new wxHtmlWindow(&dlg, wxID_ANY, wxDefaultPosition, wxSize(380, 160), wxHW_SCROLLBAR_NEVER); |
5526e819 | 167 | html -> SetBorders(0); |
2b5f62a0 | 168 | html -> LoadPage(wxT("data/about.htm")); |
0f91df4f VS |
169 | html -> SetSize(html -> GetInternalRepresentation() -> GetWidth(), |
170 | html -> GetInternalRepresentation() -> GetHeight()); | |
171 | ||
172 | topsizer -> Add(html, 1, wxALL, 10); | |
173 | ||
348469c2 | 174 | topsizer -> Add(new wxStaticLine(&dlg, wxID_ANY), 0, wxEXPAND | wxLEFT | wxRIGHT, 10); |
0f91df4f | 175 | |
2b5f62a0 | 176 | wxButton *bu1 = new wxButton(&dlg, wxID_OK, _("OK")); |
5526e819 | 177 | bu1 -> SetDefault(); |
0f91df4f VS |
178 | |
179 | topsizer -> Add(bu1, 0, wxALL | wxALIGN_RIGHT, 15); | |
180 | ||
348469c2 | 181 | dlg.SetAutoLayout(true); |
0f91df4f VS |
182 | dlg.SetSizer(topsizer); |
183 | topsizer -> Fit(&dlg); | |
184 | ||
5526e819 VS |
185 | dlg.ShowModal(); |
186 | } | |
187 |