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