1 /* -*- Mode: C; tab-width: 4 -*-
3 * Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 Change History (most recent first):
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
23 Revision 1.3 2006/08/14 23:25:28 cheshire
24 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
26 Revision 1.2 2005/03/03 19:55:22 shersche
27 <rdar://problem/4034481> ControlPanel source code isn't saving CVS log info
33 #include "ControlPanel.h"
34 #include "ConfigDialog.h"
35 #include "ConfigPropertySheet.h"
38 #include <DebugServices.h>
44 static char THIS_FILE
[] = __FILE__
;
51 //---------------------------------------------------------------------------------------------------------------------------
53 //---------------------------------------------------------------------------------------------------------------------------
58 CCPApp
* pApp
= (CCPApp
*) AfxGetApp();
61 check( pApp
->IsKindOf( RUNTIME_CLASS( CCPApp
) ) );
67 //---------------------------------------------------------------------------------------------------------------------------
69 //---------------------------------------------------------------------------------------------------------------------------
72 CPlApplet(HWND hWndCPl
, UINT uMsg
, LONG lParam1
, LONG lParam2
)
74 AFX_MANAGE_STATE(AfxGetStaticModuleState());
76 CCPApp
* pApp
= GetControlPanelApp();
78 return ( LONG
) pApp
->OnCplMsg(hWndCPl
, uMsg
, lParam1
, lParam2
);
82 IMPLEMENT_DYNAMIC(CCPApplet
, CCmdTarget
);
85 //---------------------------------------------------------------------------------------------------------------------------
86 // CCPApplet::CCPApplet
87 //---------------------------------------------------------------------------------------------------------------------------
89 CCPApplet::CCPApplet(UINT resourceId
, UINT descId
, CRuntimeClass
* uiClass
)
91 m_resourceId(resourceId
),
97 check( uiClass
->IsDerivedFrom( RUNTIME_CLASS( CDialog
) ) ||
98 uiClass
->IsDerivedFrom( RUNTIME_CLASS( CPropertySheet
) ) );
100 m_name
.LoadString(resourceId
);
104 //---------------------------------------------------------------------------------------------------------------------------
105 // CCPApplet::~CCPApplet
106 //---------------------------------------------------------------------------------------------------------------------------
108 CCPApplet::~CCPApplet()
113 //---------------------------------------------------------------------------------------------------------------------------
114 // CCPApplet::OnStartParms
115 //---------------------------------------------------------------------------------------------------------------------------
118 CCPApplet::OnStartParms(CWnd
* pParentWnd
, LPCTSTR extra
)
120 DEBUG_UNUSED( pParentWnd
);
124 m_pageNumber
= ::_ttoi( extra
) - 1;
131 //---------------------------------------------------------------------------------------------------------------------------
133 //---------------------------------------------------------------------------------------------------------------------------
136 CCPApplet::OnRun(CWnd
* pParentWnd
)
141 InitCommonControls();
143 pWnd
= (CWnd
*) m_uiClass
->CreateObject();
147 lResult
= ERROR_SUCCESS
;
149 if ( pWnd
->IsKindOf( RUNTIME_CLASS( CPropertySheet
) ) )
151 CPropertySheet
* pSheet
= (CPropertySheet
*) pWnd
;
153 pSheet
->Construct(m_name
, pParentWnd
, m_pageNumber
);
159 check( pWnd
->IsKindOf( RUNTIME_CLASS( CDialog
) ) );
161 CDialog
* pDialog
= (CDialog
*) pWnd
;
173 //---------------------------------------------------------------------------------------------------------------------------
174 // CCPApplet::OnInquire
175 //---------------------------------------------------------------------------------------------------------------------------
178 CCPApplet::OnInquire(CPLINFO
* pInfo
)
180 pInfo
->idIcon
= m_resourceId
;
181 pInfo
->idName
= m_resourceId
;
182 pInfo
->idInfo
= m_descId
;
183 pInfo
->lData
= reinterpret_cast<LONG
>(this);
189 //---------------------------------------------------------------------------------------------------------------------------
190 // CCPApplet::OnNewInquire
191 //---------------------------------------------------------------------------------------------------------------------------
194 CCPApplet::OnNewInquire(NEWCPLINFO
* pInfo
)
196 DEBUG_UNUSED( pInfo
);
202 //---------------------------------------------------------------------------------------------------------------------------
203 // CCPApplet::OnSelect
204 //---------------------------------------------------------------------------------------------------------------------------
207 CCPApplet::OnSelect()
213 //---------------------------------------------------------------------------------------------------------------------------
215 //---------------------------------------------------------------------------------------------------------------------------
224 IMPLEMENT_DYNAMIC(CCPApp
, CWinApp
);
226 //---------------------------------------------------------------------------------------------------------------------------
228 //---------------------------------------------------------------------------------------------------------------------------
232 debug_initialize( kDebugOutputTypeWindowsEventLog
, "DNS-SD Control Panel", GetModuleHandle( NULL
) );
233 debug_set_property( kDebugPropertyTagPrintLevel
, kDebugLevelInfo
);
237 //---------------------------------------------------------------------------------------------------------------------------
239 //---------------------------------------------------------------------------------------------------------------------------
243 while ( !m_applets
.IsEmpty() )
245 delete m_applets
.RemoveHead();
250 //---------------------------------------------------------------------------------------------------------------------------
252 //---------------------------------------------------------------------------------------------------------------------------
255 CCPApp::AddApplet( CCPApplet
* applet
)
259 m_applets
.AddTail( applet
);
263 //---------------------------------------------------------------------------------------------------------------------------
265 //---------------------------------------------------------------------------------------------------------------------------
274 applet
= new CCPApplet( IDR_APPLET
, IDS_APPLET_DESCRIPTION
, RUNTIME_CLASS( CConfigPropertySheet
) );
281 require_action( applet
, exit
, kNoMemoryErr
);
287 return m_applets
.GetCount();
291 //---------------------------------------------------------------------------------------------------------------------------
293 //---------------------------------------------------------------------------------------------------------------------------
302 //---------------------------------------------------------------------------------------------------------------------------
304 //---------------------------------------------------------------------------------------------------------------------------
307 CCPApp::OnCplMsg(HWND hWndCPl
, UINT uMsg
, LONG lParam1
, LONG lParam2
)
327 lResult
= m_applets
.GetCount();
333 POSITION pos
= m_applets
.FindIndex( lParam1
);
336 CCPApplet
* applet
= m_applets
.GetAt( pos
);
343 LPCPLINFO pInfo
= reinterpret_cast<LPCPLINFO
>(lParam2
);
344 lResult
= applet
->OnInquire(pInfo
);
350 LPNEWCPLINFO pInfo
= reinterpret_cast<LPNEWCPLINFO
>(lParam2
);
351 lResult
= applet
->OnNewInquire(pInfo
);
355 case CPL_STARTWPARMS
:
357 CWnd
* pParentWnd
= CWnd::FromHandle(hWndCPl
);
358 LPCTSTR lpszExtra
= reinterpret_cast<LPCTSTR
>(lParam2
);
359 lResult
= applet
->OnStartParms(pParentWnd
, lpszExtra
);
365 CWnd
* pParentWnd
= CWnd::FromHandle(hWndCPl
);
366 lResult
= applet
->OnRun(pParentWnd
);
372 lResult
= applet
->OnSelect();
378 lResult
= applet
->OnStop();
384 // TRACE(_T("Warning, Received an unknown control panel message:%d\n"), uMsg);