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