]>
git.saurik.com Git - wxWidgets.git/blob - samples/html/about/about.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtml sample: about dialog test
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
19 // for all others, include the necessary headers (this file is usually all you
20 // need because it includes almost all "standard" wxWidgets headers
26 #include "wx/imagpng.h"
27 #include "wx/wxhtml.h"
28 #include "wx/statline.h"
31 #include "../../sample.xpm"
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
40 // Define a new application type, each program should derive a class from wxApp
41 class MyApp
: public wxApp
44 // override base class virtuals
45 // ----------------------------
47 // this one is called on application startup and is a good place for the app
48 // initialization (doing it here and not in the ctor allows to have an error
49 // return: if OnInit() returns false, the application terminates)
50 virtual bool OnInit();
53 // Define a new frame type: this is going to be our main frame
54 class MyFrame
: public wxFrame
58 MyFrame(const wxString
& title
);
60 // event handlers (these functions should _not_ be virtual)
61 void OnQuit(wxCommandEvent
& event
);
62 void OnAbout(wxCommandEvent
& event
);
65 // any class wishing to process wxWidgets events must use this macro
69 // ----------------------------------------------------------------------------
70 // event tables and other macros for wxWidgets
71 // ----------------------------------------------------------------------------
73 // the event tables connect the wxWidgets events with the functions (event
74 // handlers) which process them. It can be also done at run-time, but for the
75 // simple menu events like this the static method is much simpler.
76 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
77 EVT_MENU(wxID_ABOUT
, MyFrame::OnAbout
)
78 EVT_MENU(wxID_EXIT
, MyFrame::OnQuit
)
81 // Create a new application object: this macro will allow wxWidgets to create
82 // the application object during program execution (it's better than using a
83 // static object for many reasons) and also declares the accessor function
84 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
88 // ============================================================================
90 // ============================================================================
92 // ----------------------------------------------------------------------------
93 // the application class
94 // ----------------------------------------------------------------------------
96 // `Main program' equivalent: the program execution "starts" here
99 if ( !wxApp::OnInit() )
102 // we use a PNG image in our HTML page
103 wxImage::AddHandler(new wxPNGHandler
);
105 // create and show the main application window
106 MyFrame
*frame
= new MyFrame(_("wxHtmlWindow testing application"));
109 // success: wxApp::OnRun() will be called which will enter the main message
110 // loop and the application will run. If we returned false here, the
111 // application would exit immediately.
115 // ----------------------------------------------------------------------------
117 // ----------------------------------------------------------------------------
120 MyFrame::MyFrame(const wxString
& title
)
121 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
)
123 SetIcon(wxICON(sample
));
126 wxMenu
*menuFile
= new wxMenu
;
128 menuFile
->Append(wxID_ABOUT
);
129 menuFile
->Append(wxID_EXIT
);
131 // now append the freshly created menu to the menu bar...
132 wxMenuBar
*menuBar
= new wxMenuBar
;
133 menuBar
->Append(menuFile
, _("&File"));
135 // ... and attach this menu bar to the frame
142 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
144 // true is to force the frame to close
148 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
150 wxBoxSizer
*topsizer
;
152 wxDialog
dlg(this, wxID_ANY
, wxString(_("About")));
154 topsizer
= new wxBoxSizer(wxVERTICAL
);
156 html
= new wxHtmlWindow(&dlg
, wxID_ANY
, wxDefaultPosition
, wxSize(380, 160), wxHW_SCROLLBAR_NEVER
);
157 html
-> SetBorders(0);
158 html
-> LoadPage(wxT("data/about.htm"));
159 html
-> SetSize(html
-> GetInternalRepresentation() -> GetWidth(),
160 html
-> GetInternalRepresentation() -> GetHeight());
162 topsizer
-> Add(html
, 1, wxALL
, 10);
165 topsizer
-> Add(new wxStaticLine(&dlg
, wxID_ANY
), 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
166 #endif // wxUSE_STATLINE
168 wxButton
*bu1
= new wxButton(&dlg
, wxID_OK
, _("OK"));
171 topsizer
-> Add(bu1
, 0, wxALL
| wxALIGN_RIGHT
, 15);
173 dlg
.SetSizer(topsizer
);
174 topsizer
-> Fit(&dlg
);