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