]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/applet/applet.cpp
Committing in .
[wxWidgets.git] / contrib / samples / applet / applet.cpp
1 /****************************************************************************
2 *
3 * wxWindows HTML Applet Package
4 *
5 * Copyright (C) 1991-2001 SciTech Software, Inc.
6 * All rights reserved.
7 *
8 * ========================================================================
9 *
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
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 *
20 * ========================================================================
21 *
22 * Language: ANSI C++
23 * Environment: Any
24 *
25 * Description: Main wxApplet sample program
26 *
27 ****************************************************************************/
28
29 // For compilers that support precompilation, includes "wx/wx.h".
30 #include "wx/wxprec.h"
31 #ifdef __BORLANDC__
32 #pragma hdrstop
33 #endif
34
35 #include "wx/wx.h"
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
42 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
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)
47 END_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)
54 IMPLEMENT_APP(MyApp)
55
56 /*------------------------- Implementation --------------------------------*/
57
58 /****************************************************************************
59 PARAMETERS:
60 title - Title for the frame window
61 pos - Position to place to frame window
62 size - Size of the frame window
63
64 REMARKS:
65 Application frame window constructor
66 ****************************************************************************/
67 MyFrame::MyFrame(
68 const wxString& title,
69 const wxPoint& pos,
70 const wxSize& size)
71 : wxFrame(NULL, -1, title, pos, size)
72 {
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");
79
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");
84
85 // ... and attach this menu bar to the frame
86 SetMenuBar(menuBar);
87 CreateStatusBar(2);
88
89 // Create the HTML window
90 html = new wxHtmlAppletWindow(this);
91 html->SetRelatedFrame(this, "wxApplet Demo: '%s'");
92 html->SetRelatedStatusBar(1);
93 html->LoadPage("index.html");
94 }
95
96 /****************************************************************************
97 REMARKS:
98 Event handler for the 'Exit' menu item
99 ****************************************************************************/
100 void MyFrame::OnQuit(
101 wxCommandEvent&)
102 {
103 // TRUE is to force the frame to close
104 Close(TRUE);
105 }
106
107 /****************************************************************************
108 REMARKS:
109 Event handler for the 'About' menu item
110 ****************************************************************************/
111 void MyFrame::OnAbout(
112 wxCommandEvent&)
113 {
114 // TODO: Bring up and about html page!
115 }
116
117 /****************************************************************************
118 REMARKS:
119 Event handler for the 'Go back' menu item
120 ****************************************************************************/
121 void MyFrame::OnBack(
122 wxCommandEvent&)
123 {
124 if (!html -> HistoryBack())
125 wxMessageBox("You reached prehistory era!");
126 }
127
128 /****************************************************************************
129 REMARKS:
130 Event handler for the 'Go forward' menu item
131 ****************************************************************************/
132 void MyFrame::OnForward(
133 wxCommandEvent&)
134 {
135 if (!html -> HistoryForward())
136 wxMessageBox("No more items in history!");
137 }
138
139 /****************************************************************************
140 REMARKS:
141 `Main program' equivalent: the program execution "starts" here
142 ****************************************************************************/
143 bool MyApp::OnInit()
144 {
145 // Create the main application window
146 MyFrame *frame = new MyFrame("wxApplet testing application",
147 wxPoint(50, 50), wxSize(640, 480));
148
149 // Show it and tell the application that it's our main window
150 frame->Show(TRUE);
151 SetTopWindow(frame);
152
153 // Success: wxApp::OnRun() will be called to run the application
154 return TRUE;
155 }
156