]> git.saurik.com Git - wxWidgets.git/blame - contrib/samples/applet/applet.cpp
Fixed compile problems under MingW32 compiler
[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
db157a6c
RR
35
36#include "wx/wx.h"
54921697
KB
37#include "wx/applet/window.h"
38#include "applet.h"
39
40/*---------------------------- Global variables ---------------------------*/
41
42// Define the event tables for handling application frame events
43BEGIN_EVENT_TABLE(MyFrame, wxFrame)
d20cf96f
KB
44 EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
45 EVT_MENU(Minimal_About, MyFrame::OnAbout)
46 EVT_MENU(Minimal_Back, MyFrame::OnBack)
47 EVT_MENU(Minimal_Forward, MyFrame::OnForward)
54921697
KB
48END_EVENT_TABLE()
49
50// Create a new application object: this macro will allow wxWindows to create
51// the application object during program execution (it's better than using a
52// static object for many reasons) and also declares the accessor function
53// wxGetApp() which will return the reference of the right type (i.e. MyApp and
54// not wxApp)
55IMPLEMENT_APP(MyApp)
56
57/*------------------------- Implementation --------------------------------*/
58
59/****************************************************************************
60PARAMETERS:
d20cf96f
KB
61title - Title for the frame window
62pos - Position to place to frame window
63size - Size of the frame window
54921697
KB
64
65REMARKS:
66Application frame window constructor
67****************************************************************************/
68MyFrame::MyFrame(
d20cf96f
KB
69 const wxString& title,
70 const wxPoint& pos,
71 const wxSize& size)
72 : wxFrame(NULL, -1, title, pos, size)
54921697 73{
d20cf96f
KB
74 // Create a menu bar
75 wxMenu *menuFile = new wxMenu;
76 wxMenu *menuNav = new wxMenu;
77 menuFile->Append(Minimal_Quit, "E&xit");
78 menuNav->Append(Minimal_Back, "Go &back");
79 menuNav->Append(Minimal_Forward, "Go &forward");
80
81 // Now append the freshly created menu to the menu bar...
82 wxMenuBar *menuBar = new wxMenuBar;
83 menuBar->Append(menuFile, "&File");
84 menuBar->Append(menuNav, "&Navigate");
85
86 // ... and attach this menu bar to the frame
87 SetMenuBar(menuBar);
88 CreateStatusBar(2);
89
90 // Create the HTML window
91 html = new wxHtmlAppletWindow(this);
92 html->SetRelatedFrame(this, "wxApplet Demo: '%s'");
93 html->SetRelatedStatusBar(1);
94 html->LoadPage("index.html");
54921697
KB
95}
96
97/****************************************************************************
98REMARKS:
99Event handler for the 'Exit' menu item
100****************************************************************************/
101void MyFrame::OnQuit(
d20cf96f 102 wxCommandEvent&)
54921697 103{
d20cf96f
KB
104 // TRUE is to force the frame to close
105 Close(TRUE);
54921697
KB
106}
107
108/****************************************************************************
109REMARKS:
110Event handler for the 'About' menu item
111****************************************************************************/
112void MyFrame::OnAbout(
d20cf96f 113 wxCommandEvent&)
54921697 114{
d20cf96f 115 // TODO: Bring up and about html page!
54921697
KB
116}
117
118/****************************************************************************
119REMARKS:
120Event handler for the 'Go back' menu item
121****************************************************************************/
122void MyFrame::OnBack(
d20cf96f 123 wxCommandEvent&)
54921697 124{
d20cf96f
KB
125 if (!html -> HistoryBack())
126 wxMessageBox("You reached prehistory era!");
54921697
KB
127}
128
129/****************************************************************************
130REMARKS:
131Event handler for the 'Go forward' menu item
132****************************************************************************/
133void MyFrame::OnForward(
d20cf96f 134 wxCommandEvent&)
54921697 135{
d20cf96f
KB
136 if (!html -> HistoryForward())
137 wxMessageBox("No more items in history!");
54921697
KB
138}
139
140/****************************************************************************
141REMARKS:
142`Main program' equivalent: the program execution "starts" here
143****************************************************************************/
144bool MyApp::OnInit()
145{
d20cf96f
KB
146 // Create the main application window
147 MyFrame *frame = new MyFrame("wxApplet testing application",
148 wxPoint(50, 50), wxSize(640, 480));
54921697 149
d20cf96f
KB
150 // Show it and tell the application that it's our main window
151 frame->Show(TRUE);
152 SetTopWindow(frame);
54921697 153
d20cf96f
KB
154 // Success: wxApp::OnRun() will be called to run the application
155 return TRUE;
54921697
KB
156}
157