]> git.saurik.com Git - wxWidgets.git/blame - contrib/samples/applet/applet.cpp
don't eat all events if m_maxLength is 0: this means no limit according to the docs...
[wxWidgets.git] / contrib / samples / applet / applet.cpp
CommitLineData
54921697
KB
1/****************************************************************************
2*
d20cf96f 3* wxWindows HTML Applet Package
54921697 4*
716cd410
KB
5* Copyright (C) 1991-2001 SciTech Software, Inc.
6* All rights reserved.
7*
54921697
KB
8* ========================================================================
9*
716cd410
KB
10* The contents of this file are subject to the wxWindows License
11* Version 3.0 (the "License"); you may not use this file except in
12* compliance with the License. You may obtain a copy of the License at
13* http://www.wxwindows.org/licence3.txt
54921697
KB
14*
15* Software distributed under the License is distributed on an
16* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17* implied. See the License for the specific language governing
18* rights and limitations under the License.
19*
54921697
KB
20* ========================================================================
21*
d20cf96f
KB
22* Language: ANSI C++
23* Environment: Any
54921697
KB
24*
25* Description: Main wxApplet sample program
26*
27****************************************************************************/
28
29// For compilers that support precompilation, includes "wx/wx.h".
92a19c2e 30#include "wx/wxprec.h"
54921697
KB
31#ifdef __BORLANDC__
32 #pragma hdrstop
33#endif
db157a6c
RR
34
35#include "wx/wx.h"
54921697
KB
36#include "wx/applet/window.h"
37#include "applet.h"
38
39/*---------------------------- Global variables ---------------------------*/
40
41// Define the event tables for handling application frame events
42BEGIN_EVENT_TABLE(MyFrame, wxFrame)
d20cf96f
KB
43 EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
44 EVT_MENU(Minimal_About, MyFrame::OnAbout)
45 EVT_MENU(Minimal_Back, MyFrame::OnBack)
46 EVT_MENU(Minimal_Forward, MyFrame::OnForward)
54921697
KB
47END_EVENT_TABLE()
48
49// Create a new application object: this macro will allow wxWindows to create
50// the application object during program execution (it's better than using a
51// static object for many reasons) and also declares the accessor function
52// wxGetApp() which will return the reference of the right type (i.e. MyApp and
53// not wxApp)
54IMPLEMENT_APP(MyApp)
55
56/*------------------------- Implementation --------------------------------*/
57
58/****************************************************************************
59PARAMETERS:
d20cf96f
KB
60title - Title for the frame window
61pos - Position to place to frame window
62size - Size of the frame window
54921697
KB
63
64REMARKS:
65Application frame window constructor
66****************************************************************************/
67MyFrame::MyFrame(
d20cf96f
KB
68 const wxString& title,
69 const wxPoint& pos,
70 const wxSize& size)
71 : wxFrame(NULL, -1, title, pos, size)
54921697 72{
d20cf96f
KB
73 // Create a menu bar
74 wxMenu *menuFile = new wxMenu;
75 wxMenu *menuNav = new wxMenu;
76 menuFile->Append(Minimal_Quit, "E&xit");
77 menuNav->Append(Minimal_Back, "Go &back");
78 menuNav->Append(Minimal_Forward, "Go &forward");
716cd410 79
d20cf96f
KB
80 // Now append the freshly created menu to the menu bar...
81 wxMenuBar *menuBar = new wxMenuBar;
82 menuBar->Append(menuFile, "&File");
83 menuBar->Append(menuNav, "&Navigate");
716cd410 84
d20cf96f
KB
85 // ... and attach this menu bar to the frame
86 SetMenuBar(menuBar);
87 CreateStatusBar(2);
88
716cd410 89 // Create the HTML window
d20cf96f
KB
90 html = new wxHtmlAppletWindow(this);
91 html->SetRelatedFrame(this, "wxApplet Demo: '%s'");
92 html->SetRelatedStatusBar(1);
93 html->LoadPage("index.html");
54921697
KB
94}
95
96/****************************************************************************
97REMARKS:
98Event handler for the 'Exit' menu item
99****************************************************************************/
100void MyFrame::OnQuit(
d20cf96f 101 wxCommandEvent&)
54921697 102{
d20cf96f
KB
103 // TRUE is to force the frame to close
104 Close(TRUE);
54921697
KB
105}
106
107/****************************************************************************
108REMARKS:
109Event handler for the 'About' menu item
110****************************************************************************/
111void MyFrame::OnAbout(
d20cf96f 112 wxCommandEvent&)
54921697 113{
d20cf96f 114 // TODO: Bring up and about html page!
54921697
KB
115}
116
117/****************************************************************************
118REMARKS:
119Event handler for the 'Go back' menu item
120****************************************************************************/
121void MyFrame::OnBack(
d20cf96f 122 wxCommandEvent&)
54921697 123{
d20cf96f
KB
124 if (!html -> HistoryBack())
125 wxMessageBox("You reached prehistory era!");
54921697
KB
126}
127
128/****************************************************************************
129REMARKS:
130Event handler for the 'Go forward' menu item
131****************************************************************************/
132void MyFrame::OnForward(
d20cf96f 133 wxCommandEvent&)
54921697 134{
d20cf96f
KB
135 if (!html -> HistoryForward())
136 wxMessageBox("No more items in history!");
54921697
KB
137}
138
139/****************************************************************************
140REMARKS:
141`Main program' equivalent: the program execution "starts" here
142****************************************************************************/
143bool MyApp::OnInit()
144{
d20cf96f
KB
145 // Create the main application window
146 MyFrame *frame = new MyFrame("wxApplet testing application",
147 wxPoint(50, 50), wxSize(640, 480));
54921697 148
d20cf96f
KB
149 // Show it and tell the application that it's our main window
150 frame->Show(TRUE);
151 SetTopWindow(frame);
54921697 152
d20cf96f
KB
153 // Success: wxApp::OnRun() will be called to run the application
154 return TRUE;
54921697
KB
155}
156