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