]>
git.saurik.com Git - wxWidgets.git/blob - samples/html/about/about.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtml sample: about dialog test
7 // Copyright: (c) wxWidgets team
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
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" wxWidgets headers
25 #include "wx/imagpng.h"
26 #include "wx/wxhtml.h"
27 #include "wx/statline.h"
29 #ifndef wxHAS_IMAGES_IN_RESOURCES
30 #include "../../sample.xpm"
34 // ----------------------------------------------------------------------------
36 // ----------------------------------------------------------------------------
39 // Define a new application type, each program should derive a class from wxApp
40 class MyApp
: public wxApp
43 // override base class virtuals
44 // ----------------------------
46 // this one is called on application startup and is a good place for the app
47 // initialization (doing it here and not in the ctor allows to have an error
48 // return: if OnInit() returns false, the application terminates)
49 virtual bool OnInit();
52 // Define a new frame type: this is going to be our main frame
53 class MyFrame
: public wxFrame
57 MyFrame(const wxString
& title
);
59 // event handlers (these functions should _not_ be virtual)
60 void OnQuit(wxCommandEvent
& event
);
61 void OnAbout(wxCommandEvent
& event
);
64 // any class wishing to process wxWidgets events must use this macro
68 // ----------------------------------------------------------------------------
69 // event tables and other macros for wxWidgets
70 // ----------------------------------------------------------------------------
72 // the event tables connect the wxWidgets events with the functions (event
73 // handlers) which process them. It can be also done at run-time, but for the
74 // simple menu events like this the static method is much simpler.
75 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
76 EVT_MENU(wxID_ABOUT
, MyFrame::OnAbout
)
77 EVT_MENU(wxID_EXIT
, MyFrame::OnQuit
)
80 // Create a new application object: this macro will allow wxWidgets to create
81 // the application object during program execution (it's better than using a
82 // static object for many reasons) and also declares the accessor function
83 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
87 // ============================================================================
89 // ============================================================================
91 // ----------------------------------------------------------------------------
92 // the application class
93 // ----------------------------------------------------------------------------
95 // `Main program' equivalent: the program execution "starts" here
98 if ( !wxApp::OnInit() )
101 // we use a PNG image in our HTML page
102 wxImage::AddHandler(new wxPNGHandler
);
104 // create and show the main application window
105 MyFrame
*frame
= new MyFrame(_("wxHtmlWindow testing application"));
108 // success: wxApp::OnRun() will be called which will enter the main message
109 // loop and the application will run. If we returned false here, the
110 // application would exit immediately.
114 // ----------------------------------------------------------------------------
116 // ----------------------------------------------------------------------------
119 MyFrame::MyFrame(const wxString
& title
)
120 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
)
122 SetIcon(wxICON(sample
));
125 wxMenu
*menuFile
= new wxMenu
;
127 menuFile
->Append(wxID_ABOUT
);
128 menuFile
->Append(wxID_EXIT
);
130 // now append the freshly created menu to the menu bar...
131 wxMenuBar
*menuBar
= new wxMenuBar
;
132 menuBar
->Append(menuFile
, _("&File"));
134 // ... and attach this menu bar to the frame
141 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
143 // true is to force the frame to close
147 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
149 wxBoxSizer
*topsizer
;
151 wxDialog
dlg(this, wxID_ANY
, wxString(_("About")));
153 topsizer
= new wxBoxSizer(wxVERTICAL
);
155 html
= new wxHtmlWindow(&dlg
, wxID_ANY
, wxDefaultPosition
, wxSize(380, 160), wxHW_SCROLLBAR_NEVER
);
156 html
-> SetBorders(0);
157 html
-> LoadPage(wxT("data/about.htm"));
158 html
-> SetSize(html
-> GetInternalRepresentation() -> GetWidth(),
159 html
-> GetInternalRepresentation() -> GetHeight());
161 topsizer
-> Add(html
, 1, wxALL
, 10);
164 topsizer
-> Add(new wxStaticLine(&dlg
, wxID_ANY
), 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
165 #endif // wxUSE_STATLINE
167 wxButton
*bu1
= new wxButton(&dlg
, wxID_OK
, _("OK"));
170 topsizer
-> Add(bu1
, 0, wxALL
| wxALIGN_RIGHT
, 15);
172 dlg
.SetSizer(topsizer
);
173 topsizer
-> Fit(&dlg
);