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