]> git.saurik.com Git - wxWidgets.git/blame - contrib/samples/applet/monitorapplet.cpp
fixed typo (missing comma) in MIME test
[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*
716cd410
KB
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* ========================================================================
54921697 21*
d20cf96f
KB
22* Language: ANSI C++
23* Environment: Any
54921697
KB
24*
25* Description: Main wxApplet class implementation
26*
27****************************************************************************/
28
29// For compilers that support precompilation
30#include "wx/wxprec.h"
31
32// Include private headers
db157a6c 33#include "wx/wx.h"
54921697
KB
34#include "monitorapplet.h"
35
36/*---------------------------- Global variables ---------------------------*/
37
38// Implement the dynamic class so it can be constructed dynamically
39IMPLEMENT_DYNAMIC_CLASS(MonitorApplet, wxApplet);
716cd410 40
54921697
KB
41// Event handler table.
42BEGIN_EVENT_TABLE(MonitorApplet, wxApplet)
d20cf96f
KB
43 EVT_LISTBOX(ID_LISTBOX_MFTR, MonitorApplet::OnChange)
44 EVT_LISTBOX(ID_LISTBOX_MDL, MonitorApplet::OnChange)
54921697
KB
45END_EVENT_TABLE()
46
47// Include database of known monitors. Normally this would come from a
48// real database on disk, but for this simple example we hard code all
49// the values into a table.
716cd410
KB
50#include "monitors.c"
51
54921697
KB
52/*------------------------- Implementation --------------------------------*/
53
54/****************************************************************************
55REMARKS:
56Constructor called during dynamic creation. Simple initialise all
57internal values for the class so that it can be properly created later
58via the virtual Create member function.
59****************************************************************************/
60MonitorApplet::MonitorApplet()
716cd410 61{
d20cf96f
KB
62 m_Mfr = NULL;
63 m_Model = NULL;
64 m_Data = NULL;
54921697
KB
65}
66
67/****************************************************************************
68REMARKS:
69Psuedo virtual constructor for the MonitorApplet class.
70****************************************************************************/
71bool MonitorApplet::Create(
d20cf96f
KB
72 wxHtmlAppletWindow *parent,
73 const wxSize& size,
74 long style)
54921697
KB
75{
76 bool ret = wxApplet::Create(parent, size, style);
77 if (ret) {
d20cf96f
KB
78 // Read our cookie or create it if it does not exist
79 if ((m_Data = (MonitorData*)parent->FindCookie(MONITOR_COOKIE_NAME)) == NULL) {
80 m_Data = new MonitorData;
81 memset(&m_Data->m_Monitor,0,sizeof(m_Data->m_Monitor));
82 parent->RegisterCookie(MONITOR_COOKIE_NAME,m_Data);
83 }
716cd410 84
d20cf96f
KB
85 // Create all the controls and initialise them
86 MonitorDialogFunc(this,true,true);
87 if ((m_Mfr = new ComboBox(this , ID_LISTBOX_MFTR, ID_TEXTCTRL_MFTR)) == NULL)
88 return false;
89 if ((m_Model = new ComboBox(this , ID_LISTBOX_MDL, ID_TEXTCTRL_MDL)) == NULL)
90 return false;
91 ReadMfrList();
92 ReadModelList(true);
93 }
54921697
KB
94 return ret;
95}
716cd410 96
54921697
KB
97/****************************************************************************
98REMARKS:
99Destructor for the MonitorApplet class.
100****************************************************************************/
101MonitorApplet::~MonitorApplet()
102{
d20cf96f
KB
103 delete m_Mfr;
104 delete m_Model;
54921697
KB
105}
106
107/****************************************************************************
108REMARKS:
109Save the current state for the applet to our cookie
110****************************************************************************/
111void MonitorApplet::SaveCurrentState()
112{
d20cf96f 113 // Read currently selected strings into cookie
54921697
KB
114 strcpy(m_Data->m_Monitor.m_Mfr,m_Mfr->GetStringSelection());
115 strcpy(m_Data->m_Monitor.m_Model,m_Model->GetStringSelection());
116}
117
118/****************************************************************************
119REMARKS:
120Handles user navigation away from the applet via an HTML link
121****************************************************************************/
122void MonitorApplet::OnLinkClicked(
716cd410 123 const wxHtmlLinkInfo&)
54921697 124{
d20cf96f 125 SaveCurrentState();
54921697 126}
716cd410 127
54921697
KB
128/****************************************************************************
129REMARKS:
130Handles user navigation away from the applet via the history forward command
131****************************************************************************/
132void MonitorApplet::OnHistoryForward()
133{
d20cf96f 134 SaveCurrentState();
54921697 135}
716cd410 136
54921697
KB
137/****************************************************************************
138REMARKS:
139Handles user navigation away from the applet via the history back command
140****************************************************************************/
141void MonitorApplet::OnHistoryBack()
142{
d20cf96f 143 SaveCurrentState();
54921697 144}
716cd410 145
54921697
KB
146/****************************************************************************
147REMARKS:
148Handles inter applet communication messages
149****************************************************************************/
716cd410 150void MonitorApplet::OnMessage(
d20cf96f 151 wxEvent& msg)
54921697 152{
d20cf96f 153 msg.Skip(true);
54921697
KB
154}
155
156/****************************************************************************
157REMARKS:
158****************************************************************************/
159void MonitorApplet::OnChange(
d20cf96f 160 wxCommandEvent &evt)
54921697 161{
d20cf96f
KB
162 if (evt.GetId() == m_Mfr->GetListBoxId()) {
163 m_Mfr->OnChange(evt);
164 ReadModelList(true);
165 }
166 else if (evt.GetId() == m_Model->GetListBoxId()) {
716cd410 167 m_Model->OnChange(evt);
d20cf96f 168 }
54921697
KB
169}
170
171/****************************************************************************
172REMARKS:
173Updates the manufacturer list for the dialog box from the database.
174****************************************************************************/
175void MonitorApplet::ReadMfrList()
716cd410 176{
d20cf96f
KB
177 char buf[80] = "";
178 int i,selected = 0;
179 MonitorEntry *m;
54921697
KB
180
181 m_Mfr->Clear();
d20cf96f 182 for (m = m_Monitors,i = 0; m->m_Mfr[0] != 0; m++) {
db157a6c 183 if (wxStricmp(buf,m->m_Mfr) != 0) {
54921697 184 m_Mfr->Append(m->m_Mfr);
db157a6c 185 if (wxStricmp(m_Data->m_Monitor.m_Mfr,m->m_Mfr) == 0)
d20cf96f
KB
186 selected = i;
187 strcpy(buf,m->m_Mfr);
188 i++;
189 }
190 }
54921697
KB
191 m_Mfr->Select(selected);
192}
193
194/****************************************************************************
195REMARKS:
196Updates the model list for the dialog box for the currently selected
197manufacturer type.
198****************************************************************************/
199void MonitorApplet::ReadModelList(
200 bool selectCurrent)
716cd410 201{
d20cf96f
KB
202 int i,selected = 0;
203 MonitorEntry *m;
204 wxString mfrStr;
716cd410 205
d20cf96f 206 mfrStr = m_Mfr->GetStringSelection();
54921697 207 m_Model->Clear();
d20cf96f 208 for (m = m_Monitors,i = 0; m->m_Mfr[0] != 0; m++) {
db157a6c 209 if (wxStricmp(mfrStr,m->m_Mfr) == 0) {
54921697 210 m_Model->Append(m->m_Model);
db157a6c 211 if (selectCurrent && wxStricmp(m_Data->m_Monitor.m_Model,m->m_Model) == 0)
d20cf96f
KB
212 selected = i;
213 i++;
214 }
215 }
54921697
KB
216 m_Model->Select(selected);
217}
218