]> git.saurik.com Git - wxWidgets.git/blame - samples/html/widget/widget.cpp
added wxUSE_COMBOBCONTROL and wxUSE_OWNERDRAWNCOMBOBOX to wx/setup.h files
[wxWidgets.git] / samples / html / widget / widget.cpp
CommitLineData
5526e819 1/////////////////////////////////////////////////////////////////////////////
59815218 2// Name: widget.cpp
5526e819 3// Purpose: wxHtml testing example
59815218 4// Demonstrates embedded controls
5526e819
VS
5/////////////////////////////////////////////////////////////////////////////
6
5526e819 7// For compilers that support precompilation, includes "wx/wx.h".
92a19c2e 8#include "wx/wxprec.h"
5526e819
VS
9
10#ifdef __BORLANDC__
11 #pragma hdrstop
12#endif
13
14// for all others, include the necessary headers (this file is usually all you
be5a51fb 15// need because it includes almost all "standard" wxWidgets headers
5526e819 16#ifndef WX_PRECOMP
67547666 17 #include "wx/wx.h"
5526e819
VS
18#endif
19
20
67547666 21#include "wx/html/htmlwin.h"
5526e819 22
59815218
JS
23#include "../../sample.xpm"
24
5526e819 25
5526e819
VS
26/*
27
28
29TAG HANDER FOR 'MYBIND' TAG
30
31
32*/
33
67547666 34#include "wx/html/m_templ.h"
5526e819
VS
35
36
37TAG_HANDLER_BEGIN(MYBIND, "MYBIND")
38
aec18ff7
MB
39TAG_HANDLER_PROC(tag)
40{
41 wxWindow *wnd;
42 int ax, ay;
43 int fl = 0;
44
45 tag.ScanParam(wxT("X"), wxT("%i"), &ax);
46 tag.ScanParam(wxT("Y"), wxT("%i"), &ay);
47
48 if (tag.HasParam(wxT("FLOAT"))) fl = ax;
5526e819 49
5e888f8e
VS
50 wnd = new wxTextCtrl
51 (
52 m_WParser->GetWindowInterface()->GetHTMLWindow(),
53 wxID_ANY,
54 tag.GetParam(wxT("NAME")),
55 wxPoint(0,0),
56 wxSize(ax, ay),
57 wxTE_MULTILINE
58 );
5526e819 59
52fa6f7d 60 wnd->Show(true);
5526e819 61
aec18ff7 62 m_WParser->GetContainer()->InsertCell(new wxHtmlWidgetCell(wnd, fl));
5526e819 63
52fa6f7d 64 return false;
aec18ff7 65}
5526e819
VS
66
67TAG_HANDLER_END(MYBIND)
68
69
70
71TAGS_MODULE_BEGIN(MyBind)
72
73 TAGS_MODULE_ADD(MYBIND)
74
75TAGS_MODULE_END(MyBind)
76
77
5526e819
VS
78// ----------------------------------------------------------------------------
79// private classes
80// ----------------------------------------------------------------------------
81
82// Define a new application type, each program should derive a class from wxApp
aec18ff7
MB
83class MyApp : public wxApp
84{
85public:
5526e819
VS
86 // override base class virtuals
87 // ----------------------------
aec18ff7 88
5526e819
VS
89 // this one is called on application startup and is a good place for the app
90 // initialization (doing it here and not in the ctor allows to have an error
91 // return: if OnInit() returns false, the application terminates)
aec18ff7
MB
92 virtual bool OnInit();
93};
5526e819
VS
94
95// Define a new frame type: this is going to be our main frame
aec18ff7
MB
96class MyFrame : public wxFrame
97{
98public:
5526e819 99 // ctor(s)
aec18ff7
MB
100 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
101
5526e819 102 // event handlers (these functions should _not_ be virtual)
aec18ff7
MB
103 void OnQuit(wxCommandEvent& event);
104 void OnBack(wxCommandEvent& event);
105 void OnForward(wxCommandEvent& event);
5526e819 106
aec18ff7 107private:
be5a51fb 108 // any class wishing to process wxWidgets events must use this macro
5526e819 109 DECLARE_EVENT_TABLE()
aec18ff7 110};
5526e819
VS
111
112// ----------------------------------------------------------------------------
113// constants
114// ----------------------------------------------------------------------------
115
116// IDs for the controls and the menu commands
aec18ff7
MB
117enum
118{
5526e819 119 // menu items
aec18ff7
MB
120 Minimal_Quit = 1,
121 Minimal_Back,
122 Minimal_Forward,
123
5526e819 124 // controls start here (the numbers are, of course, arbitrary)
aec18ff7
MB
125 Minimal_Text = 1000,
126};
5526e819
VS
127
128// ----------------------------------------------------------------------------
be5a51fb 129// event tables and other macros for wxWidgets
5526e819
VS
130// ----------------------------------------------------------------------------
131
be5a51fb 132// the event tables connect the wxWidgets events with the functions (event
5526e819
VS
133// handlers) which process them. It can be also done at run-time, but for the
134// simple menu events like this the static method is much simpler.
aec18ff7
MB
135BEGIN_EVENT_TABLE(MyFrame, wxFrame)
136 EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
137 EVT_MENU(Minimal_Back, MyFrame::OnBack)
138 EVT_MENU(Minimal_Forward, MyFrame::OnForward)
139END_EVENT_TABLE()
140
be5a51fb 141// Create a new application object: this macro will allow wxWidgets to create
aec18ff7
MB
142// the application object during program execution (it's better than using a
143// static object for many reasons) and also declares the accessor function
144// wxGetApp() which will return the reference of the right type (i.e. MyApp and
145// not wxApp)
146IMPLEMENT_APP(MyApp)
147
148// ============================================================================
149// implementation
150// ============================================================================
151
152// ----------------------------------------------------------------------------
153// the application class
154// ----------------------------------------------------------------------------
155
156// `Main program' equivalent: the program execution "starts" here
157bool MyApp::OnInit()
158{
5526e819 159 // Create the main application window
2b5f62a0 160 MyFrame *frame = new MyFrame( _("wxHtmlWindow testing application"),
16f26dad 161 wxDefaultPosition, wxSize(640, 480) );
aec18ff7 162
5526e819
VS
163 // Show it and tell the application that it's our main window
164 // @@@ what does it do exactly, in fact? is it necessary here?
52fa6f7d 165 frame->Show(true);
aec18ff7 166 SetTopWindow(frame);
5526e819
VS
167
168 // success: wxApp::OnRun() will be called which will enter the main message
52fa6f7d 169 // loop and the application will run. If we returned false here, the
5526e819 170 // application would exit immediately.
52fa6f7d 171 return true;
aec18ff7 172}
5526e819
VS
173
174// ----------------------------------------------------------------------------
175// main frame
176// ----------------------------------------------------------------------------
177
178wxHtmlWindow *html;
179
180// frame constructor
aec18ff7 181MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
52fa6f7d 182: wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size)
aec18ff7 183{
5526e819 184 // create a menu bar
aec18ff7
MB
185 wxMenu *menuFile = new wxMenu;
186 wxMenu *menuNav = new wxMenu;
5526e819 187
2b5f62a0
VZ
188 menuFile->Append(Minimal_Quit, _("E&xit"));
189 menuNav->Append(Minimal_Back, _("Go &BACK"));
190 menuNav->Append(Minimal_Forward, _("Go &FORWARD"));
5526e819
VS
191
192 // now append the freshly created menu to the menu bar...
aec18ff7 193 wxMenuBar *menuBar = new wxMenuBar;
2b5f62a0
VZ
194 menuBar->Append(menuFile, _("&File"));
195 menuBar->Append(menuNav, _("&Navigate"));
5526e819
VS
196
197 // ... and attach this menu bar to the frame
aec18ff7 198 SetMenuBar(menuBar);
5526e819 199
59815218
JS
200 SetIcon(wxIcon(sample_xpm));
201
8520f137 202#if wxUSE_STATUSBAR
aec18ff7 203 CreateStatusBar(2);
8520f137 204#endif // wxUSE_STATUSBAR
aec18ff7
MB
205
206 html = new wxHtmlWindow(this);
59815218 207 html -> SetRelatedFrame(this, _("wxHTML Demo: '%s'"));
8520f137 208#if wxUSE_STATUSBAR
aec18ff7 209 html -> SetRelatedStatusBar(1);
8520f137 210#endif // wxUSE_STATUSBAR
2b5f62a0 211 html -> LoadPage(wxT("start.htm"));
59815218 212
aec18ff7 213}
5526e819
VS
214
215
216// event handlers
217
aec18ff7
MB
218void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
219{
52fa6f7d
WS
220 // true is to force the frame to close
221 Close(true);
aec18ff7 222}
5526e819 223
aec18ff7
MB
224void MyFrame::OnBack(wxCommandEvent& WXUNUSED(event))
225{
2b5f62a0 226 if (!html -> HistoryBack()) wxMessageBox(_("You reached prehistory era!"));
aec18ff7 227}
5526e819
VS
228
229
aec18ff7
MB
230void MyFrame::OnForward(wxCommandEvent& WXUNUSED(event))
231{
2b5f62a0 232 if (!html -> HistoryForward()) wxMessageBox(_("No more items in history!"));
aec18ff7 233}