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