]> git.saurik.com Git - wxWidgets.git/blob - samples/html/about/about.cpp
Added Makefile for gcc-win
[wxWidgets.git] / samples / html / about / about.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: test.cpp
3 // Purpose: wxHtml testing example
4 /////////////////////////////////////////////////////////////////////////////
5
6 #ifdef __GNUG__
7 #pragma implementation "test.cpp"
8 #pragma interface "test.cpp"
9 #endif
10
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include <wx/wxprec.h>
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
21 #include <wx/wx.h>
22 #endif
23
24 #include <wx/image.h>
25 #include <wx/wxhtml.h>
26
27 // ----------------------------------------------------------------------------
28 // private classes
29 // ----------------------------------------------------------------------------
30
31
32 // Define a new application type, each program should derive a class from wxApp
33 class MyApp : public wxApp
34 {
35 public:
36 // override base class virtuals
37 // ----------------------------
38
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();
43 };
44
45 // Define a new frame type: this is going to be our main frame
46 class MyFrame : public wxFrame
47 {
48 public:
49 // ctor(s)
50 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
51
52 // event handlers (these functions should _not_ be virtual)
53 void OnQuit(wxCommandEvent& event);
54 void OnAbout(wxCommandEvent& event);
55
56 private:
57 // any class wishing to process wxWindows events must use this macro
58 DECLARE_EVENT_TABLE()
59 };
60
61 // ----------------------------------------------------------------------------
62 // constants
63 // ----------------------------------------------------------------------------
64
65 // IDs for the controls and the menu commands
66 enum
67 {
68 // menu items
69 Minimal_Quit = 1,
70 Minimal_About,
71 Minimal_Back,
72 Minimal_Forward,
73
74 // controls start here (the numbers are, of course, arbitrary)
75 Minimal_Text = 1000,
76 };
77
78 // ----------------------------------------------------------------------------
79 // event tables and other macros for wxWindows
80 // ----------------------------------------------------------------------------
81
82 // the event tables connect the wxWindows events with the functions (event
83 // handlers) which process them. It can be also done at run-time, but for the
84 // simple menu events like this the static method is much simpler.
85 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
86 EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
87 EVT_MENU(Minimal_About, MyFrame::OnAbout)
88 END_EVENT_TABLE()
89
90 // Create a new application object: this macro will allow wxWindows to create
91 // the application object during program execution (it's better than using a
92 // static object for many reasons) and also declares the accessor function
93 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
94 // not wxApp)
95 IMPLEMENT_APP(MyApp)
96
97 // ============================================================================
98 // implementation
99 // ============================================================================
100
101 // ----------------------------------------------------------------------------
102 // the application class
103 // ----------------------------------------------------------------------------
104 // `Main program' equivalent: the program execution "starts" here
105 bool MyApp::OnInit()
106 {
107 wxImage::AddHandler(new wxPNGHandler);
108 // Create the main application window
109 MyFrame *frame = new MyFrame("wxHtmlWindow testing application",
110 wxPoint(50, 50), wxSize(150, 50));
111
112 // Show it and tell the application that it's our main window
113 // @@@ what does it do exactly, in fact? is it necessary here?
114 frame->Show(TRUE);
115 SetTopWindow(frame);
116
117
118 // success: wxApp::OnRun() will be called which will enter the main message
119 // loop and the application will run. If we returned FALSE here, the
120 // application would exit immediately.
121 return TRUE;
122 }
123
124 // ----------------------------------------------------------------------------
125 // main frame
126 // ----------------------------------------------------------------------------
127
128
129 // frame constructor
130 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
131 : wxFrame((wxFrame *)NULL, -1, title, pos, size)
132 {
133 // create a menu bar
134 wxMenu *menuFile = new wxMenu;
135
136 menuFile->Append(Minimal_About, "&About");
137 menuFile->Append(Minimal_Quit, "E&xit");
138
139 // now append the freshly created menu to the menu bar...
140 wxMenuBar *menuBar = new wxMenuBar;
141 menuBar->Append(menuFile, "&File");
142
143 // ... and attach this menu bar to the frame
144 SetMenuBar(menuBar);
145 }
146
147
148 // event handlers
149
150 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
151 {
152 // TRUE is to force the frame to close
153 Close(TRUE);
154 }
155
156 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
157 {
158 wxHtmlWindow *html;
159 #if __WXMSW__
160 wxDialog dlg(this, -1, "About", wxDefaultPosition, wxSize(400, 250), wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE);
161 #else
162 wxDialog dlg(this, -1, "About", wxDefaultPosition, wxSize(400, 230), wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE);
163 #endif
164
165 html = new wxHtmlWindow(&dlg, -1, wxPoint(10, 10), wxSize(380, 160), "htmlWindow", FALSE);
166 html -> SetBorders(0);
167 html -> LoadPage("data/about.htm");
168 wxButton *bu1 = new wxButton(&dlg, wxID_OK, "OK", wxPoint(250, 185), wxSize(100, 30));
169 bu1 -> SetDefault();
170 dlg.ShowModal();
171 }
172
173
174
175
176
177
178