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