]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSWindows/ControlPanel/ControlPanel.cpp
mDNSResponder-107.tar.gz
[apple/mdnsresponder.git] / mDNSWindows / ControlPanel / ControlPanel.cpp
1 /*
2 * Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22
23 Change History (most recent first):
24
25 $Log: ControlPanel.cpp,v $
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 = (CWnd*) m_uiClass->CreateObject();
140
141 if ( pWnd )
142 {
143 lResult = ERROR_SUCCESS;
144
145 if ( pWnd->IsKindOf( RUNTIME_CLASS( CPropertySheet ) ) )
146 {
147 CPropertySheet * pSheet = (CPropertySheet*) pWnd;
148
149 pSheet->Construct(m_name, pParentWnd, m_pageNumber);
150
151 pSheet->DoModal();
152 }
153 else
154 {
155 check( pWnd->IsKindOf( RUNTIME_CLASS( CDialog ) ) );
156
157 CDialog * pDialog = (CDialog*) pWnd;
158
159 pDialog->DoModal();
160 }
161
162 delete pWnd;
163 }
164
165 return lResult;
166 }
167
168
169 //---------------------------------------------------------------------------------------------------------------------------
170 // CCPApplet::OnInquire
171 //---------------------------------------------------------------------------------------------------------------------------
172
173 LRESULT
174 CCPApplet::OnInquire(CPLINFO* pInfo)
175 {
176 pInfo->idIcon = m_resourceId;
177 pInfo->idName = m_resourceId;
178 pInfo->idInfo = m_descId;
179 pInfo->lData = reinterpret_cast<LONG>(this);
180
181 return 0;
182 }
183
184
185 //---------------------------------------------------------------------------------------------------------------------------
186 // CCPApplet::OnNewInquire
187 //---------------------------------------------------------------------------------------------------------------------------
188
189 LRESULT
190 CCPApplet::OnNewInquire(NEWCPLINFO* pInfo)
191 {
192 DEBUG_UNUSED( pInfo );
193
194 return 1;
195 }
196
197
198 //---------------------------------------------------------------------------------------------------------------------------
199 // CCPApplet::OnSelect
200 //---------------------------------------------------------------------------------------------------------------------------
201
202 LRESULT
203 CCPApplet::OnSelect()
204 {
205 return 0;
206 }
207
208
209 //---------------------------------------------------------------------------------------------------------------------------
210 // CCPApplet::OnStop
211 //---------------------------------------------------------------------------------------------------------------------------
212
213 LRESULT
214 CCPApplet::OnStop()
215 {
216 return 0;
217 }
218
219
220 IMPLEMENT_DYNAMIC(CCPApp, CWinApp);
221
222 //---------------------------------------------------------------------------------------------------------------------------
223 // CCPApp::CCPApp
224 //---------------------------------------------------------------------------------------------------------------------------
225
226 CCPApp::CCPApp()
227 {
228 debug_initialize( kDebugOutputTypeWindowsEventLog, "DNS-SD Control Panel", GetModuleHandle( NULL ) );
229 debug_set_property( kDebugPropertyTagPrintLevel, kDebugLevelInfo );
230 }
231
232
233 //---------------------------------------------------------------------------------------------------------------------------
234 // CCPApp::~CCPApp
235 //---------------------------------------------------------------------------------------------------------------------------
236
237 CCPApp::~CCPApp()
238 {
239 while ( !m_applets.IsEmpty() )
240 {
241 delete m_applets.RemoveHead();
242 }
243 }
244
245
246 //---------------------------------------------------------------------------------------------------------------------------
247 // CCPApp::AddApplet
248 //---------------------------------------------------------------------------------------------------------------------------
249
250 void
251 CCPApp::AddApplet( CCPApplet * applet )
252 {
253 check( applet );
254
255 m_applets.AddTail( applet );
256 }
257
258
259 //---------------------------------------------------------------------------------------------------------------------------
260 // CCPApp::OnInit
261 //---------------------------------------------------------------------------------------------------------------------------
262
263 LRESULT
264 CCPApp::OnInit()
265 {
266 CCPApplet * applet;
267
268 try
269 {
270 applet = new CCPApplet( IDR_APPLET, IDS_APPLET_DESCRIPTION, RUNTIME_CLASS( CConfigPropertySheet ) );
271 }
272 catch (...)
273 {
274 applet = NULL;
275 }
276
277 require_action( applet, exit, kNoMemoryErr );
278
279 AddApplet( applet );
280
281 exit:
282
283 return m_applets.GetCount();
284 }
285
286
287 //---------------------------------------------------------------------------------------------------------------------------
288 // CCPApp::OnExit
289 //---------------------------------------------------------------------------------------------------------------------------
290
291 LRESULT
292 CCPApp::OnExit()
293 {
294 return 1;
295 }
296
297
298 //---------------------------------------------------------------------------------------------------------------------------
299 // CCPApp::OnCplMsg
300 //---------------------------------------------------------------------------------------------------------------------------
301
302 LRESULT
303 CCPApp::OnCplMsg(HWND hWndCPl, UINT uMsg, LONG lParam1, LONG lParam2)
304 {
305 LRESULT lResult = 1;
306
307 switch ( uMsg )
308 {
309 case CPL_INIT:
310 {
311 lResult = OnInit();
312 }
313 break;
314
315 case CPL_EXIT:
316 {
317 lResult = OnExit();
318 }
319 break;
320
321 case CPL_GETCOUNT:
322 {
323 lResult = m_applets.GetCount();
324 }
325 break;
326
327 default:
328 {
329 POSITION pos = m_applets.FindIndex( lParam1 );
330 check( pos );
331
332 CCPApplet * applet = m_applets.GetAt( pos );
333 check( applet );
334
335 switch (uMsg)
336 {
337 case CPL_INQUIRE:
338 {
339 LPCPLINFO pInfo = reinterpret_cast<LPCPLINFO>(lParam2);
340 lResult = applet->OnInquire(pInfo);
341 }
342 break;
343
344 case CPL_NEWINQUIRE:
345 {
346 LPNEWCPLINFO pInfo = reinterpret_cast<LPNEWCPLINFO>(lParam2);
347 lResult = applet->OnNewInquire(pInfo);
348 }
349 break;
350
351 case CPL_STARTWPARMS:
352 {
353 CWnd * pParentWnd = CWnd::FromHandle(hWndCPl);
354 LPCTSTR lpszExtra = reinterpret_cast<LPCTSTR>(lParam2);
355 lResult = applet->OnStartParms(pParentWnd, lpszExtra);
356 }
357 break;
358
359 case CPL_DBLCLK:
360 {
361 CWnd* pParentWnd = CWnd::FromHandle(hWndCPl);
362 lResult = applet->OnRun(pParentWnd);
363 }
364 break;
365
366 case CPL_SELECT:
367 {
368 lResult = applet->OnSelect();
369 }
370 break;
371
372 case CPL_STOP:
373 {
374 lResult = applet->OnStop();
375 }
376 break;
377
378 default:
379 {
380 // TRACE(_T("Warning, Received an unknown control panel message:%d\n"), uMsg);
381 lResult = 1;
382 }
383 break;
384 }
385 }
386 break;
387 }
388
389 return lResult;
390 }