]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSWindows/ControlPanel/ControlPanel.cpp
mDNSResponder-212.1.tar.gz
[apple/mdnsresponder.git] / mDNSWindows / ControlPanel / ControlPanel.cpp
1 /* -*- Mode: C; tab-width: 4 -*-
2 *
3 * Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16
17 Change History (most recent first):
18
19 $Log: ControlPanel.cpp,v $
20 Revision 1.5 2009/03/30 20:00:19 herscher
21 <rdar://problem/5925472> Current Bonjour code does not compile on Windows
22 <rdar://problem/5187308> Move build train to Visual Studio 2005
23
24 Revision 1.4 2007/04/27 20:42:11 herscher
25 <rdar://problem/5078828> mDNS: Bonjour Control Panel for Windows doesn't work on Vista
26
27 Revision 1.3 2006/08/14 23:25:28 cheshire
28 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
29
30 Revision 1.2 2005/03/03 19:55:22 shersche
31 <rdar://problem/4034481> ControlPanel source code isn't saving CVS log info
32
33
34 */
35
36
37 #include "ControlPanel.h"
38 #include "ConfigDialog.h"
39 #include "ConfigPropertySheet.h"
40 #include "resource.h"
41
42 #include <DebugServices.h>
43
44
45 #ifdef _DEBUG
46 #define new DEBUG_NEW
47 #undef THIS_FILE
48 static char THIS_FILE[] = __FILE__;
49 #endif
50
51
52 static CCPApp theApp;
53
54
55 //---------------------------------------------------------------------------------------------------------------------------
56 // GetControlPanelApp
57 //---------------------------------------------------------------------------------------------------------------------------
58
59 CCPApp*
60 GetControlPanelApp()
61 {
62 CCPApp * pApp = (CCPApp*) AfxGetApp();
63
64 check( pApp );
65 check( pApp->IsKindOf( RUNTIME_CLASS( CCPApp ) ) );
66
67 return pApp;
68 }
69
70
71 //---------------------------------------------------------------------------------------------------------------------------
72 // CPlApplet
73 //---------------------------------------------------------------------------------------------------------------------------
74
75 LONG APIENTRY
76 CPlApplet(HWND hWndCPl, UINT uMsg, LONG lParam1, LONG lParam2)
77 {
78 AFX_MANAGE_STATE(AfxGetStaticModuleState());
79
80 CCPApp * pApp = GetControlPanelApp();
81
82 return ( LONG ) pApp->OnCplMsg(hWndCPl, uMsg, lParam1, lParam2);
83 }
84
85
86 IMPLEMENT_DYNAMIC(CCPApplet, CCmdTarget);
87
88
89 //---------------------------------------------------------------------------------------------------------------------------
90 // CCPApplet::CCPApplet
91 //---------------------------------------------------------------------------------------------------------------------------
92
93 CCPApplet::CCPApplet(UINT resourceId, UINT descId, CRuntimeClass * uiClass)
94 :
95 m_resourceId(resourceId),
96 m_descId(descId),
97 m_uiClass(uiClass),
98 m_pageNumber(0)
99 {
100 check( uiClass );
101 check( uiClass->IsDerivedFrom( RUNTIME_CLASS( CDialog ) ) ||
102 uiClass->IsDerivedFrom( RUNTIME_CLASS( CPropertySheet ) ) );
103
104 m_name.LoadString(resourceId);
105 }
106
107
108 //---------------------------------------------------------------------------------------------------------------------------
109 // CCPApplet::~CCPApplet
110 //---------------------------------------------------------------------------------------------------------------------------
111
112 CCPApplet::~CCPApplet()
113 {
114 }
115
116
117 //---------------------------------------------------------------------------------------------------------------------------
118 // CCPApplet::OnStartParms
119 //---------------------------------------------------------------------------------------------------------------------------
120
121 LRESULT
122 CCPApplet::OnStartParms(CWnd * pParentWnd, LPCTSTR extra)
123 {
124 DEBUG_UNUSED( pParentWnd );
125
126 if ( extra )
127 {
128 m_pageNumber = ::_ttoi( extra ) - 1;
129 }
130
131 return 0;
132 }
133
134
135 //---------------------------------------------------------------------------------------------------------------------------
136 // CCPApplet::OnRun
137 //---------------------------------------------------------------------------------------------------------------------------
138
139 LRESULT
140 CCPApplet::OnRun(CWnd* pParentWnd)
141 {
142 LRESULT lResult = 1;
143 CWnd * pWnd;
144
145 InitCommonControls();
146
147 pWnd = (CWnd*) m_uiClass->CreateObject();
148
149 if ( pWnd )
150 {
151 lResult = ERROR_SUCCESS;
152
153 if ( pWnd->IsKindOf( RUNTIME_CLASS( CPropertySheet ) ) )
154 {
155 CPropertySheet * pSheet = (CPropertySheet*) pWnd;
156
157 pSheet->Construct(m_name, pParentWnd, m_pageNumber);
158
159 pSheet->DoModal();
160 }
161 else
162 {
163 check( pWnd->IsKindOf( RUNTIME_CLASS( CDialog ) ) );
164
165 CDialog * pDialog = (CDialog*) pWnd;
166
167 pDialog->DoModal();
168 }
169
170 delete pWnd;
171 }
172
173 return lResult;
174 }
175
176
177 //---------------------------------------------------------------------------------------------------------------------------
178 // CCPApplet::OnInquire
179 //---------------------------------------------------------------------------------------------------------------------------
180
181 LRESULT
182 CCPApplet::OnInquire(CPLINFO* pInfo)
183 {
184 pInfo->idIcon = m_resourceId;
185 pInfo->idName = m_resourceId;
186 pInfo->idInfo = m_descId;
187 pInfo->lData = reinterpret_cast<LONG>(this);
188
189 return 0;
190 }
191
192
193 //---------------------------------------------------------------------------------------------------------------------------
194 // CCPApplet::OnNewInquire
195 //---------------------------------------------------------------------------------------------------------------------------
196
197 LRESULT
198 CCPApplet::OnNewInquire(NEWCPLINFO* pInfo)
199 {
200 DEBUG_UNUSED( pInfo );
201
202 return 1;
203 }
204
205
206 //---------------------------------------------------------------------------------------------------------------------------
207 // CCPApplet::OnSelect
208 //---------------------------------------------------------------------------------------------------------------------------
209
210 LRESULT
211 CCPApplet::OnSelect()
212 {
213 return 0;
214 }
215
216
217 //---------------------------------------------------------------------------------------------------------------------------
218 // CCPApplet::OnStop
219 //---------------------------------------------------------------------------------------------------------------------------
220
221 LRESULT
222 CCPApplet::OnStop()
223 {
224 return 0;
225 }
226
227
228 IMPLEMENT_DYNAMIC(CCPApp, CWinApp);
229
230 //---------------------------------------------------------------------------------------------------------------------------
231 // CCPApp::CCPApp
232 //---------------------------------------------------------------------------------------------------------------------------
233
234 CCPApp::CCPApp()
235 {
236 debug_initialize( kDebugOutputTypeWindowsEventLog, "DNS-SD Control Panel", GetModuleHandle( NULL ) );
237 debug_set_property( kDebugPropertyTagPrintLevel, kDebugLevelInfo );
238 }
239
240
241 //---------------------------------------------------------------------------------------------------------------------------
242 // CCPApp::~CCPApp
243 //---------------------------------------------------------------------------------------------------------------------------
244
245 CCPApp::~CCPApp()
246 {
247 while ( !m_applets.IsEmpty() )
248 {
249 delete m_applets.RemoveHead();
250 }
251 }
252
253
254 //---------------------------------------------------------------------------------------------------------------------------
255 // CCPApp::AddApplet
256 //---------------------------------------------------------------------------------------------------------------------------
257
258 void
259 CCPApp::AddApplet( CCPApplet * applet )
260 {
261 check( applet );
262
263 m_applets.AddTail( applet );
264 }
265
266
267 //---------------------------------------------------------------------------------------------------------------------------
268 // CCPApp::OnInit
269 //---------------------------------------------------------------------------------------------------------------------------
270
271 LRESULT
272 CCPApp::OnInit()
273 {
274 CCPApplet * applet;
275
276 try
277 {
278 applet = new CCPApplet( IDR_APPLET, IDS_APPLET_DESCRIPTION, RUNTIME_CLASS( CConfigPropertySheet ) );
279 }
280 catch (...)
281 {
282 applet = NULL;
283 }
284
285 require_action( applet, exit, kNoMemoryErr );
286
287 AddApplet( applet );
288
289 exit:
290
291 return m_applets.GetCount();
292 }
293
294
295 //---------------------------------------------------------------------------------------------------------------------------
296 // CCPApp::OnExit
297 //---------------------------------------------------------------------------------------------------------------------------
298
299 LRESULT
300 CCPApp::OnExit()
301 {
302 return 1;
303 }
304
305
306 //---------------------------------------------------------------------------------------------------------------------------
307 // CCPApp::OnCplMsg
308 //---------------------------------------------------------------------------------------------------------------------------
309
310 LRESULT
311 CCPApp::OnCplMsg(HWND hWndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
312 {
313 LRESULT lResult = 1;
314
315 switch ( uMsg )
316 {
317 case CPL_INIT:
318 {
319 lResult = OnInit();
320 }
321 break;
322
323 case CPL_EXIT:
324 {
325 lResult = OnExit();
326 }
327 break;
328
329 case CPL_GETCOUNT:
330 {
331 lResult = m_applets.GetCount();
332 }
333 break;
334
335 default:
336 {
337 POSITION pos = m_applets.FindIndex( lParam1 );
338 check( pos );
339
340 CCPApplet * applet = m_applets.GetAt( pos );
341 check( applet );
342
343 switch (uMsg)
344 {
345 case CPL_INQUIRE:
346 {
347 LPCPLINFO pInfo = reinterpret_cast<LPCPLINFO>(lParam2);
348 lResult = applet->OnInquire(pInfo);
349 }
350 break;
351
352 case CPL_NEWINQUIRE:
353 {
354 LPNEWCPLINFO pInfo = reinterpret_cast<LPNEWCPLINFO>(lParam2);
355 lResult = applet->OnNewInquire(pInfo);
356 }
357 break;
358
359 case CPL_STARTWPARMS:
360 {
361 CWnd * pParentWnd = CWnd::FromHandle(hWndCPl);
362 LPCTSTR lpszExtra = reinterpret_cast<LPCTSTR>(lParam2);
363 lResult = applet->OnStartParms(pParentWnd, lpszExtra);
364 }
365 break;
366
367 case CPL_DBLCLK:
368 {
369 CWnd* pParentWnd = CWnd::FromHandle(hWndCPl);
370 lResult = applet->OnRun(pParentWnd);
371 }
372 break;
373
374 case CPL_SELECT:
375 {
376 lResult = applet->OnSelect();
377 }
378 break;
379
380 case CPL_STOP:
381 {
382 lResult = applet->OnStop();
383 }
384 break;
385
386 default:
387 {
388 // TRACE(_T("Warning, Received an unknown control panel message:%d\n"), uMsg);
389 lResult = 1;
390 }
391 break;
392 }
393 }
394 break;
395 }
396
397 return lResult;
398 }