]>
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 * ========================================================================
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
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.
20 * ========================================================================
25 * Description: Main wxApplet class implementation
27 ****************************************************************************/
29 // For compilers that support precompilation
30 #include "wx/wxprec.h"
32 // Include private headers
34 #include "monitorapplet.h"
36 /*---------------------------- Global variables ---------------------------*/
38 // Implement the dynamic class so it can be constructed dynamically
39 IMPLEMENT_DYNAMIC_CLASS(MonitorApplet
, wxApplet
)
41 // Event handler table.
42 BEGIN_EVENT_TABLE(MonitorApplet
, wxApplet
)
43 EVT_LISTBOX(ID_LISTBOX_MFTR
, MonitorApplet::OnChange
)
44 EVT_LISTBOX(ID_LISTBOX_MDL
, MonitorApplet::OnChange
)
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.
52 /*------------------------- Implementation --------------------------------*/
54 /****************************************************************************
56 Constructor called during dynamic creation. Simple initialise all
57 internal values for the class so that it can be properly created later
58 via the virtual Create member function.
59 ****************************************************************************/
60 MonitorApplet::MonitorApplet()
67 /****************************************************************************
69 Psuedo virtual constructor for the MonitorApplet class.
70 ****************************************************************************/
71 bool MonitorApplet::Create(
72 wxHtmlAppletWindow
*parent
,
76 bool ret
= wxApplet::Create(parent
, size
, style
);
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
);
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
)
89 if ((m_Model
= new ComboBox(this , ID_LISTBOX_MDL
, ID_TEXTCTRL_MDL
)) == NULL
)
97 /****************************************************************************
99 Destructor for the MonitorApplet class.
100 ****************************************************************************/
101 MonitorApplet::~MonitorApplet()
107 /****************************************************************************
109 Save the current state for the applet to our cookie
110 ****************************************************************************/
111 void MonitorApplet::SaveCurrentState()
113 // Read currently selected strings into cookie
114 strcpy(m_Data
->m_Monitor
.m_Mfr
,m_Mfr
->GetStringSelection());
115 strcpy(m_Data
->m_Monitor
.m_Model
,m_Model
->GetStringSelection());
118 /****************************************************************************
120 Handles user navigation away from the applet via an HTML link
121 ****************************************************************************/
122 void MonitorApplet::OnLinkClicked(
123 const wxHtmlLinkInfo
&)
128 /****************************************************************************
130 Handles user navigation away from the applet via the history forward command
131 ****************************************************************************/
132 void MonitorApplet::OnHistoryForward()
137 /****************************************************************************
139 Handles user navigation away from the applet via the history back command
140 ****************************************************************************/
141 void MonitorApplet::OnHistoryBack()
146 /****************************************************************************
148 Handles inter applet communication messages
149 ****************************************************************************/
150 void MonitorApplet::OnMessage(
156 /****************************************************************************
158 ****************************************************************************/
159 void MonitorApplet::OnChange(
162 if (evt
.GetId() == m_Mfr
->GetListBoxId()) {
163 m_Mfr
->OnChange(evt
);
166 else if (evt
.GetId() == m_Model
->GetListBoxId()) {
167 m_Model
->OnChange(evt
);
171 /****************************************************************************
173 Updates the manufacturer list for the dialog box from the database.
174 ****************************************************************************/
175 void MonitorApplet::ReadMfrList()
182 for (m
= m_Monitors
,i
= 0; m
->m_Mfr
[0] != 0; m
++) {
183 if (wxStricmp(buf
,m
->m_Mfr
) != 0) {
184 m_Mfr
->Append(m
->m_Mfr
);
185 if (wxStricmp(m_Data
->m_Monitor
.m_Mfr
,m
->m_Mfr
) == 0)
187 strcpy(buf
,m
->m_Mfr
);
191 m_Mfr
->Select(selected
);
194 /****************************************************************************
196 Updates the model list for the dialog box for the currently selected
198 ****************************************************************************/
199 void MonitorApplet::ReadModelList(
206 mfrStr
= m_Mfr
->GetStringSelection();
208 for (m
= m_Monitors
,i
= 0; m
->m_Mfr
[0] != 0; m
++) {
209 if (wxStricmp(mfrStr
,m
->m_Mfr
) == 0) {
210 m_Model
->Append(m
->m_Model
);
211 if (selectCurrent
&& wxStricmp(m_Data
->m_Monitor
.m_Model
,m
->m_Model
) == 0)
216 m_Model
->Select(selected
);