]> git.saurik.com Git - wxWidgets.git/blame - contrib/samples/applet/monitorapplet.cpp
reverted the hack for accepting broken HHC files (new wxHF_xxxx flags provide same...
[wxWidgets.git] / contrib / samples / applet / monitorapplet.cpp
CommitLineData
54921697
KB
1/****************************************************************************
2*
d20cf96f 3* wxWindows HTML Applet Package
54921697
KB
4*
5* Copyright (C) 1991-2001 SciTech Software, Inc.
6* All rights reserved.
7*
8* ======================================================================
9* |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW|
10* | |
11* |This copyrighted computer code is a proprietary trade secret of |
12* |SciTech Software, Inc., located at 505 Wall Street, Chico, CA 95928 |
13* |USA (www.scitechsoft.com). ANY UNAUTHORIZED POSSESSION, USE, |
14* |VIEWING, COPYING, MODIFICATION OR DISSEMINATION OF THIS CODE IS |
15* |STRICTLY PROHIBITED BY LAW. Unless you have current, express |
16* |written authorization from SciTech to possess or use this code, you |
17* |may be subject to civil and/or criminal penalties. |
18* | |
19* |If you received this code in error or you would like to report |
20* |improper use, please immediately contact SciTech Software, Inc. at |
21* |530-894-8400. |
22* | |
23* |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW|
24* ======================================================================
25*
d20cf96f
KB
26* Language: ANSI C++
27* Environment: Any
54921697
KB
28*
29* Description: Main wxApplet class implementation
30*
31****************************************************************************/
32
33// For compilers that support precompilation
34#include "wx/wxprec.h"
35
36// Include private headers
37#include "monitorapplet.h"
38
39/*---------------------------- Global variables ---------------------------*/
40
41// Implement the dynamic class so it can be constructed dynamically
42IMPLEMENT_DYNAMIC_CLASS(MonitorApplet, wxApplet);
d20cf96f 43
54921697
KB
44// Event handler table.
45BEGIN_EVENT_TABLE(MonitorApplet, wxApplet)
d20cf96f
KB
46 EVT_LISTBOX(ID_LISTBOX_MFTR, MonitorApplet::OnChange)
47 EVT_LISTBOX(ID_LISTBOX_MDL, MonitorApplet::OnChange)
54921697
KB
48END_EVENT_TABLE()
49
50// Include database of known monitors. Normally this would come from a
51// real database on disk, but for this simple example we hard code all
52// the values into a table.
d20cf96f
KB
53#include "monitors.c"
54
54921697
KB
55/*------------------------- Implementation --------------------------------*/
56
57/****************************************************************************
58REMARKS:
59Constructor called during dynamic creation. Simple initialise all
60internal values for the class so that it can be properly created later
61via the virtual Create member function.
62****************************************************************************/
63MonitorApplet::MonitorApplet()
d20cf96f
KB
64{
65 m_Mfr = NULL;
66 m_Model = NULL;
67 m_Data = NULL;
54921697
KB
68}
69
70/****************************************************************************
71REMARKS:
72Psuedo virtual constructor for the MonitorApplet class.
73****************************************************************************/
74bool MonitorApplet::Create(
d20cf96f
KB
75 wxHtmlAppletWindow *parent,
76 const wxSize& size,
77 long style)
54921697
KB
78{
79 bool ret = wxApplet::Create(parent, size, style);
80 if (ret) {
d20cf96f
KB
81 // Read our cookie or create it if it does not exist
82 if ((m_Data = (MonitorData*)parent->FindCookie(MONITOR_COOKIE_NAME)) == NULL) {
83 m_Data = new MonitorData;
84 memset(&m_Data->m_Monitor,0,sizeof(m_Data->m_Monitor));
85 parent->RegisterCookie(MONITOR_COOKIE_NAME,m_Data);
86 }
87
88 // Create all the controls and initialise them
89 MonitorDialogFunc(this,true,true);
90 if ((m_Mfr = new ComboBox(this , ID_LISTBOX_MFTR, ID_TEXTCTRL_MFTR)) == NULL)
91 return false;
92 if ((m_Model = new ComboBox(this , ID_LISTBOX_MDL, ID_TEXTCTRL_MDL)) == NULL)
93 return false;
94 ReadMfrList();
95 ReadModelList(true);
96 }
54921697
KB
97 return ret;
98}
d20cf96f 99
54921697
KB
100/****************************************************************************
101REMARKS:
102Destructor for the MonitorApplet class.
103****************************************************************************/
104MonitorApplet::~MonitorApplet()
105{
d20cf96f
KB
106 delete m_Mfr;
107 delete m_Model;
54921697
KB
108}
109
110/****************************************************************************
111REMARKS:
112Save the current state for the applet to our cookie
113****************************************************************************/
114void MonitorApplet::SaveCurrentState()
115{
d20cf96f 116 // Read currently selected strings into cookie
54921697
KB
117 strcpy(m_Data->m_Monitor.m_Mfr,m_Mfr->GetStringSelection());
118 strcpy(m_Data->m_Monitor.m_Model,m_Model->GetStringSelection());
119}
120
121/****************************************************************************
122REMARKS:
123Handles user navigation away from the applet via an HTML link
124****************************************************************************/
125void MonitorApplet::OnLinkClicked(
d20cf96f 126 const wxHtmlLinkInfo&)
54921697 127{
d20cf96f 128 SaveCurrentState();
54921697 129}
d20cf96f 130
54921697
KB
131/****************************************************************************
132REMARKS:
133Handles user navigation away from the applet via the history forward command
134****************************************************************************/
135void MonitorApplet::OnHistoryForward()
136{
d20cf96f 137 SaveCurrentState();
54921697 138}
d20cf96f 139
54921697
KB
140/****************************************************************************
141REMARKS:
142Handles user navigation away from the applet via the history back command
143****************************************************************************/
144void MonitorApplet::OnHistoryBack()
145{
d20cf96f 146 SaveCurrentState();
54921697 147}
d20cf96f 148
54921697
KB
149/****************************************************************************
150REMARKS:
151Handles inter applet communication messages
152****************************************************************************/
d20cf96f
KB
153void MonitorApplet::OnMessage(
154 wxEvent& msg)
54921697 155{
d20cf96f 156 msg.Skip(true);
54921697
KB
157}
158
159/****************************************************************************
160REMARKS:
161****************************************************************************/
162void MonitorApplet::OnChange(
d20cf96f 163 wxCommandEvent &evt)
54921697 164{
d20cf96f
KB
165 if (evt.GetId() == m_Mfr->GetListBoxId()) {
166 m_Mfr->OnChange(evt);
167 ReadModelList(true);
168 }
169 else if (evt.GetId() == m_Model->GetListBoxId()) {
170 m_Model->OnChange(evt);
171 }
54921697
KB
172}
173
174/****************************************************************************
175REMARKS:
176Updates the manufacturer list for the dialog box from the database.
177****************************************************************************/
178void MonitorApplet::ReadMfrList()
d20cf96f
KB
179{
180 char buf[80] = "";
181 int i,selected = 0;
182 MonitorEntry *m;
54921697
KB
183
184 m_Mfr->Clear();
d20cf96f
KB
185 for (m = m_Monitors,i = 0; m->m_Mfr[0] != 0; m++) {
186 if (stricmp(buf,m->m_Mfr) != 0) {
54921697 187 m_Mfr->Append(m->m_Mfr);
d20cf96f
KB
188 if (stricmp(m_Data->m_Monitor.m_Mfr,m->m_Mfr) == 0)
189 selected = i;
190 strcpy(buf,m->m_Mfr);
191 i++;
192 }
193 }
54921697
KB
194 m_Mfr->Select(selected);
195}
196
197/****************************************************************************
198REMARKS:
199Updates the model list for the dialog box for the currently selected
200manufacturer type.
201****************************************************************************/
202void MonitorApplet::ReadModelList(
203 bool selectCurrent)
d20cf96f
KB
204{
205 int i,selected = 0;
206 MonitorEntry *m;
207 wxString mfrStr;
208
209 mfrStr = m_Mfr->GetStringSelection();
54921697 210 m_Model->Clear();
d20cf96f
KB
211 for (m = m_Monitors,i = 0; m->m_Mfr[0] != 0; m++) {
212 if (stricmp(mfrStr,m->m_Mfr) == 0) {
54921697 213 m_Model->Append(m->m_Model);
d20cf96f
KB
214 if (selectCurrent && stricmp(m_Data->m_Monitor.m_Model,m->m_Model) == 0)
215 selected = i;
216 i++;
217 }
218 }
54921697
KB
219 m_Model->Select(selected);
220}
221