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.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
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
27 Revision 1.3 2006/08/14 23:25:28 cheshire
28 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
30 Revision 1.2 2005/03/03 19:55:22 shersche
31 <rdar://problem/4034481> ControlPanel source code isn't saving CVS log info
37 #include "ControlPanel.h"
38 #include "ConfigDialog.h"
39 #include "ConfigPropertySheet.h"
42 #include <DebugServices.h>
48 static char THIS_FILE
[] = __FILE__
;
55 //---------------------------------------------------------------------------------------------------------------------------
57 //---------------------------------------------------------------------------------------------------------------------------
62 CCPApp
* pApp
= (CCPApp
*) AfxGetApp();
65 check( pApp
->IsKindOf( RUNTIME_CLASS( CCPApp
) ) );
71 //---------------------------------------------------------------------------------------------------------------------------
73 //---------------------------------------------------------------------------------------------------------------------------
76 CPlApplet(HWND hWndCPl
, UINT uMsg
, LONG lParam1
, LONG lParam2
)
78 AFX_MANAGE_STATE(AfxGetStaticModuleState());
80 CCPApp
* pApp
= GetControlPanelApp();
82 return ( LONG
) pApp
->OnCplMsg(hWndCPl
, uMsg
, lParam1
, lParam2
);
86 IMPLEMENT_DYNAMIC(CCPApplet
, CCmdTarget
);
89 //---------------------------------------------------------------------------------------------------------------------------
90 // CCPApplet::CCPApplet
91 //---------------------------------------------------------------------------------------------------------------------------
93 CCPApplet::CCPApplet(UINT resourceId
, UINT descId
, CRuntimeClass
* uiClass
)
95 m_resourceId(resourceId
),
101 check( uiClass
->IsDerivedFrom( RUNTIME_CLASS( CDialog
) ) ||
102 uiClass
->IsDerivedFrom( RUNTIME_CLASS( CPropertySheet
) ) );
104 m_name
.LoadString(resourceId
);
108 //---------------------------------------------------------------------------------------------------------------------------
109 // CCPApplet::~CCPApplet
110 //---------------------------------------------------------------------------------------------------------------------------
112 CCPApplet::~CCPApplet()
117 //---------------------------------------------------------------------------------------------------------------------------
118 // CCPApplet::OnStartParms
119 //---------------------------------------------------------------------------------------------------------------------------
122 CCPApplet::OnStartParms(CWnd
* pParentWnd
, LPCTSTR extra
)
124 DEBUG_UNUSED( pParentWnd
);
128 m_pageNumber
= ::_ttoi( extra
) - 1;
135 //---------------------------------------------------------------------------------------------------------------------------
137 //---------------------------------------------------------------------------------------------------------------------------
140 CCPApplet::OnRun(CWnd
* pParentWnd
)
145 InitCommonControls();
147 pWnd
= (CWnd
*) m_uiClass
->CreateObject();
151 lResult
= ERROR_SUCCESS
;
153 if ( pWnd
->IsKindOf( RUNTIME_CLASS( CPropertySheet
) ) )
155 CPropertySheet
* pSheet
= (CPropertySheet
*) pWnd
;
157 pSheet
->Construct(m_name
, pParentWnd
, m_pageNumber
);
163 check( pWnd
->IsKindOf( RUNTIME_CLASS( CDialog
) ) );
165 CDialog
* pDialog
= (CDialog
*) pWnd
;
177 //---------------------------------------------------------------------------------------------------------------------------
178 // CCPApplet::OnInquire
179 //---------------------------------------------------------------------------------------------------------------------------
182 CCPApplet::OnInquire(CPLINFO
* pInfo
)
184 pInfo
->idIcon
= m_resourceId
;
185 pInfo
->idName
= m_resourceId
;
186 pInfo
->idInfo
= m_descId
;
187 pInfo
->lData
= reinterpret_cast<LONG
>(this);
193 //---------------------------------------------------------------------------------------------------------------------------
194 // CCPApplet::OnNewInquire
195 //---------------------------------------------------------------------------------------------------------------------------
198 CCPApplet::OnNewInquire(NEWCPLINFO
* pInfo
)
200 DEBUG_UNUSED( pInfo
);
206 //---------------------------------------------------------------------------------------------------------------------------
207 // CCPApplet::OnSelect
208 //---------------------------------------------------------------------------------------------------------------------------
211 CCPApplet::OnSelect()
217 //---------------------------------------------------------------------------------------------------------------------------
219 //---------------------------------------------------------------------------------------------------------------------------
228 IMPLEMENT_DYNAMIC(CCPApp
, CWinApp
);
230 //---------------------------------------------------------------------------------------------------------------------------
232 //---------------------------------------------------------------------------------------------------------------------------
236 debug_initialize( kDebugOutputTypeWindowsEventLog
, "DNS-SD Control Panel", GetModuleHandle( NULL
) );
237 debug_set_property( kDebugPropertyTagPrintLevel
, kDebugLevelInfo
);
241 //---------------------------------------------------------------------------------------------------------------------------
243 //---------------------------------------------------------------------------------------------------------------------------
247 while ( !m_applets
.IsEmpty() )
249 delete m_applets
.RemoveHead();
254 //---------------------------------------------------------------------------------------------------------------------------
256 //---------------------------------------------------------------------------------------------------------------------------
259 CCPApp::AddApplet( CCPApplet
* applet
)
263 m_applets
.AddTail( applet
);
267 //---------------------------------------------------------------------------------------------------------------------------
269 //---------------------------------------------------------------------------------------------------------------------------
278 applet
= new CCPApplet( IDR_APPLET
, IDS_APPLET_DESCRIPTION
, RUNTIME_CLASS( CConfigPropertySheet
) );
285 require_action( applet
, exit
, kNoMemoryErr
);
291 return m_applets
.GetCount();
295 //---------------------------------------------------------------------------------------------------------------------------
297 //---------------------------------------------------------------------------------------------------------------------------
306 //---------------------------------------------------------------------------------------------------------------------------
308 //---------------------------------------------------------------------------------------------------------------------------
311 CCPApp::OnCplMsg(HWND hWndCPl
, UINT uMsg
, LPARAM lParam1
, LPARAM lParam2
)
331 lResult
= m_applets
.GetCount();
337 POSITION pos
= m_applets
.FindIndex( lParam1
);
340 CCPApplet
* applet
= m_applets
.GetAt( pos
);
347 LPCPLINFO pInfo
= reinterpret_cast<LPCPLINFO
>(lParam2
);
348 lResult
= applet
->OnInquire(pInfo
);
354 LPNEWCPLINFO pInfo
= reinterpret_cast<LPNEWCPLINFO
>(lParam2
);
355 lResult
= applet
->OnNewInquire(pInfo
);
359 case CPL_STARTWPARMS
:
361 CWnd
* pParentWnd
= CWnd::FromHandle(hWndCPl
);
362 LPCTSTR lpszExtra
= reinterpret_cast<LPCTSTR
>(lParam2
);
363 lResult
= applet
->OnStartParms(pParentWnd
, lpszExtra
);
369 CWnd
* pParentWnd
= CWnd::FromHandle(hWndCPl
);
370 lResult
= applet
->OnRun(pParentWnd
);
376 lResult
= applet
->OnSelect();
382 lResult
= applet
->OnStop();
388 // TRACE(_T("Warning, Received an unknown control panel message:%d\n"), uMsg);