]>
git.saurik.com Git - wxWidgets.git/blob - contrib/samples/applet/monitorapplet.cpp
1 /****************************************************************************
3 * wxWindows HTML Applet Package
5 * Copyright (C) 1991-2001 SciTech Software, Inc.
8 * ======================================================================
9 * |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW|
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. |
19 * |If you received this code in error or you would like to report |
20 * |improper use, please immediately contact SciTech Software, Inc. at |
23 * |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW|
24 * ======================================================================
29 * Description: Main wxApplet class implementation
31 ****************************************************************************/
33 // For compilers that support precompilation
34 #include "wx/wxprec.h"
36 // Include private headers
37 #include "monitorapplet.h"
39 /*---------------------------- Global variables ---------------------------*/
41 // Implement the dynamic class so it can be constructed dynamically
42 IMPLEMENT_DYNAMIC_CLASS(MonitorApplet
, wxApplet
);
44 // Event handler table.
45 BEGIN_EVENT_TABLE(MonitorApplet
, wxApplet
)
46 EVT_LISTBOX(ID_LISTBOX_MFTR
, MonitorApplet::OnChange
)
47 EVT_LISTBOX(ID_LISTBOX_MDL
, MonitorApplet::OnChange
)
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.
55 /*------------------------- Implementation --------------------------------*/
57 /****************************************************************************
59 Constructor called during dynamic creation. Simple initialise all
60 internal values for the class so that it can be properly created later
61 via the virtual Create member function.
62 ****************************************************************************/
63 MonitorApplet::MonitorApplet()
70 /****************************************************************************
72 Psuedo virtual constructor for the MonitorApplet class.
73 ****************************************************************************/
74 bool MonitorApplet::Create(
75 wxHtmlAppletWindow
*parent
,
79 bool ret
= wxApplet::Create(parent
, size
, style
);
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
);
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
)
92 if ((m_Model
= new ComboBox(this , ID_LISTBOX_MDL
, ID_TEXTCTRL_MDL
)) == NULL
)
100 /****************************************************************************
102 Destructor for the MonitorApplet class.
103 ****************************************************************************/
104 MonitorApplet::~MonitorApplet()
110 /****************************************************************************
112 Save the current state for the applet to our cookie
113 ****************************************************************************/
114 void MonitorApplet::SaveCurrentState()
116 // Read currently selected strings into cookie
117 strcpy(m_Data
->m_Monitor
.m_Mfr
,m_Mfr
->GetStringSelection());
118 strcpy(m_Data
->m_Monitor
.m_Model
,m_Model
->GetStringSelection());
121 /****************************************************************************
123 Handles user navigation away from the applet via an HTML link
124 ****************************************************************************/
125 void MonitorApplet::OnLinkClicked(
126 const wxHtmlLinkInfo
&)
131 /****************************************************************************
133 Handles user navigation away from the applet via the history forward command
134 ****************************************************************************/
135 void MonitorApplet::OnHistoryForward()
140 /****************************************************************************
142 Handles user navigation away from the applet via the history back command
143 ****************************************************************************/
144 void MonitorApplet::OnHistoryBack()
149 /****************************************************************************
151 Handles inter applet communication messages
152 ****************************************************************************/
153 void MonitorApplet::OnMessage(
159 /****************************************************************************
161 ****************************************************************************/
162 void MonitorApplet::OnChange(
165 if (evt
.GetId() == m_Mfr
->GetListBoxId()) {
166 m_Mfr
->OnChange(evt
);
169 else if (evt
.GetId() == m_Model
->GetListBoxId()) {
170 m_Model
->OnChange(evt
);
174 /****************************************************************************
176 Updates the manufacturer list for the dialog box from the database.
177 ****************************************************************************/
178 void MonitorApplet::ReadMfrList()
185 for (m
= m_Monitors
,i
= 0; m
->m_Mfr
[0] != 0; m
++) {
186 if (stricmp(buf
,m
->m_Mfr
) != 0) {
187 m_Mfr
->Append(m
->m_Mfr
);
188 if (stricmp(m_Data
->m_Monitor
.m_Mfr
,m
->m_Mfr
) == 0)
190 strcpy(buf
,m
->m_Mfr
);
194 m_Mfr
->Select(selected
);
197 /****************************************************************************
199 Updates the model list for the dialog box for the currently selected
201 ****************************************************************************/
202 void MonitorApplet::ReadModelList(
209 mfrStr
= m_Mfr
->GetStringSelection();
211 for (m
= m_Monitors
,i
= 0; m
->m_Mfr
[0] != 0; m
++) {
212 if (stricmp(mfrStr
,m
->m_Mfr
) == 0) {
213 m_Model
->Append(m
->m_Model
);
214 if (selectCurrent
&& stricmp(m_Data
->m_Monitor
.m_Model
,m
->m_Model
) == 0)
219 m_Model
->Select(selected
);