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.
19 #include "ControlPanel.h"
20 #include "ConfigDialog.h"
21 #include "ConfigPropertySheet.h"
24 #include <DebugServices.h>
30 static char THIS_FILE[] = __FILE__;
37 //---------------------------------------------------------------------------------------------------------------------------
39 //---------------------------------------------------------------------------------------------------------------------------
44 CCPApp * pApp = (CCPApp*) AfxGetApp();
47 check( pApp->IsKindOf( RUNTIME_CLASS( CCPApp ) ) );
53 //---------------------------------------------------------------------------------------------------------------------------
55 //---------------------------------------------------------------------------------------------------------------------------
58 CPlApplet(HWND hWndCPl, UINT uMsg, LONG lParam1, LONG lParam2)
60 AFX_MANAGE_STATE(AfxGetStaticModuleState());
62 CCPApp * pApp = GetControlPanelApp();
64 return ( LONG ) pApp->OnCplMsg(hWndCPl, uMsg, lParam1, lParam2);
68 IMPLEMENT_DYNAMIC(CCPApplet, CCmdTarget);
71 //---------------------------------------------------------------------------------------------------------------------------
72 // CCPApplet::CCPApplet
73 //---------------------------------------------------------------------------------------------------------------------------
75 CCPApplet::CCPApplet(UINT resourceId, UINT descId, CRuntimeClass * uiClass)
77 m_resourceId(resourceId),
83 check( uiClass->IsDerivedFrom( RUNTIME_CLASS( CDialog ) ) ||
84 uiClass->IsDerivedFrom( RUNTIME_CLASS( CPropertySheet ) ) );
86 m_name.LoadString(resourceId);
90 //---------------------------------------------------------------------------------------------------------------------------
91 // CCPApplet::~CCPApplet
92 //---------------------------------------------------------------------------------------------------------------------------
94 CCPApplet::~CCPApplet()
99 //---------------------------------------------------------------------------------------------------------------------------
100 // CCPApplet::OnStartParms
101 //---------------------------------------------------------------------------------------------------------------------------
104 CCPApplet::OnStartParms(CWnd * pParentWnd, LPCTSTR extra)
106 DEBUG_UNUSED( pParentWnd );
110 m_pageNumber = ::_ttoi( extra ) - 1;
117 //---------------------------------------------------------------------------------------------------------------------------
119 //---------------------------------------------------------------------------------------------------------------------------
122 CCPApplet::OnRun(CWnd* pParentWnd)
127 InitCommonControls();
129 pWnd = (CWnd*) m_uiClass->CreateObject();
133 lResult = ERROR_SUCCESS;
135 if ( pWnd->IsKindOf( RUNTIME_CLASS( CPropertySheet ) ) )
137 CPropertySheet * pSheet = (CPropertySheet*) pWnd;
139 pSheet->Construct(m_name, pParentWnd, m_pageNumber);
145 check( pWnd->IsKindOf( RUNTIME_CLASS( CDialog ) ) );
147 CDialog * pDialog = (CDialog*) pWnd;
159 //---------------------------------------------------------------------------------------------------------------------------
160 // CCPApplet::OnInquire
161 //---------------------------------------------------------------------------------------------------------------------------
164 CCPApplet::OnInquire(CPLINFO* pInfo)
166 pInfo->idIcon = m_resourceId;
167 pInfo->idName = m_resourceId;
168 pInfo->idInfo = m_descId;
169 pInfo->lData = reinterpret_cast<LONG>(this);
175 //---------------------------------------------------------------------------------------------------------------------------
176 // CCPApplet::OnNewInquire
177 //---------------------------------------------------------------------------------------------------------------------------
180 CCPApplet::OnNewInquire(NEWCPLINFO* pInfo)
182 DEBUG_UNUSED( pInfo );
188 //---------------------------------------------------------------------------------------------------------------------------
189 // CCPApplet::OnSelect
190 //---------------------------------------------------------------------------------------------------------------------------
193 CCPApplet::OnSelect()
199 //---------------------------------------------------------------------------------------------------------------------------
201 //---------------------------------------------------------------------------------------------------------------------------
210 IMPLEMENT_DYNAMIC(CCPApp, CWinApp);
212 //---------------------------------------------------------------------------------------------------------------------------
214 //---------------------------------------------------------------------------------------------------------------------------
218 debug_initialize( kDebugOutputTypeWindowsEventLog, "DNS-SD Control Panel", GetModuleHandle( NULL ) );
219 debug_set_property( kDebugPropertyTagPrintLevel, kDebugLevelInfo );
223 //---------------------------------------------------------------------------------------------------------------------------
225 //---------------------------------------------------------------------------------------------------------------------------
229 while ( !m_applets.IsEmpty() )
231 delete m_applets.RemoveHead();
236 //---------------------------------------------------------------------------------------------------------------------------
238 //---------------------------------------------------------------------------------------------------------------------------
241 CCPApp::AddApplet( CCPApplet * applet )
245 m_applets.AddTail( applet );
249 //---------------------------------------------------------------------------------------------------------------------------
251 //---------------------------------------------------------------------------------------------------------------------------
260 applet = new CCPApplet( IDR_APPLET, IDS_APPLET_DESCRIPTION, RUNTIME_CLASS( CConfigPropertySheet ) );
267 require_action( applet, exit, kNoMemoryErr );
273 return m_applets.GetCount();
277 //---------------------------------------------------------------------------------------------------------------------------
279 //---------------------------------------------------------------------------------------------------------------------------
288 //---------------------------------------------------------------------------------------------------------------------------
290 //---------------------------------------------------------------------------------------------------------------------------
293 CCPApp::OnCplMsg(HWND hWndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
313 lResult = m_applets.GetCount();
319 POSITION pos = m_applets.FindIndex( lParam1 );
322 CCPApplet * applet = m_applets.GetAt( pos );
329 LPCPLINFO pInfo = reinterpret_cast<LPCPLINFO>(lParam2);
330 lResult = applet->OnInquire(pInfo);
336 LPNEWCPLINFO pInfo = reinterpret_cast<LPNEWCPLINFO>(lParam2);
337 lResult = applet->OnNewInquire(pInfo);
341 case CPL_STARTWPARMS:
343 CWnd * pParentWnd = CWnd::FromHandle(hWndCPl);
344 LPCTSTR lpszExtra = reinterpret_cast<LPCTSTR>(lParam2);
345 lResult = applet->OnStartParms(pParentWnd, lpszExtra);
351 CWnd* pParentWnd = CWnd::FromHandle(hWndCPl);
352 lResult = applet->OnRun(pParentWnd);
358 lResult = applet->OnSelect();
364 lResult = applet->OnStop();
370 // TRACE(_T("Warning, Received an unknown control panel message:%d\n"), uMsg);