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.3 2006/08/14 23:25:28 cheshire
21 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
23 Revision 1.2 2005/03/03 19:55:22 shersche
24 <rdar://problem/4034481> ControlPanel source code isn't saving CVS log info
30 #include "ControlPanel.h"
31 #include "ConfigDialog.h"
32 #include "ConfigPropertySheet.h"
35 #include <DebugServices.h>
41 static char THIS_FILE
[] = __FILE__
;
48 //---------------------------------------------------------------------------------------------------------------------------
50 //---------------------------------------------------------------------------------------------------------------------------
55 CCPApp
* pApp
= (CCPApp
*) AfxGetApp();
58 check( pApp
->IsKindOf( RUNTIME_CLASS( CCPApp
) ) );
64 //---------------------------------------------------------------------------------------------------------------------------
66 //---------------------------------------------------------------------------------------------------------------------------
69 CPlApplet(HWND hWndCPl
, UINT uMsg
, LONG lParam1
, LONG lParam2
)
71 AFX_MANAGE_STATE(AfxGetStaticModuleState());
73 CCPApp
* pApp
= GetControlPanelApp();
75 return ( LONG
) pApp
->OnCplMsg(hWndCPl
, uMsg
, lParam1
, lParam2
);
79 IMPLEMENT_DYNAMIC(CCPApplet
, CCmdTarget
);
82 //---------------------------------------------------------------------------------------------------------------------------
83 // CCPApplet::CCPApplet
84 //---------------------------------------------------------------------------------------------------------------------------
86 CCPApplet::CCPApplet(UINT resourceId
, UINT descId
, CRuntimeClass
* uiClass
)
88 m_resourceId(resourceId
),
94 check( uiClass
->IsDerivedFrom( RUNTIME_CLASS( CDialog
) ) ||
95 uiClass
->IsDerivedFrom( RUNTIME_CLASS( CPropertySheet
) ) );
97 m_name
.LoadString(resourceId
);
101 //---------------------------------------------------------------------------------------------------------------------------
102 // CCPApplet::~CCPApplet
103 //---------------------------------------------------------------------------------------------------------------------------
105 CCPApplet::~CCPApplet()
110 //---------------------------------------------------------------------------------------------------------------------------
111 // CCPApplet::OnStartParms
112 //---------------------------------------------------------------------------------------------------------------------------
115 CCPApplet::OnStartParms(CWnd
* pParentWnd
, LPCTSTR extra
)
117 DEBUG_UNUSED( pParentWnd
);
121 m_pageNumber
= ::_ttoi( extra
) - 1;
128 //---------------------------------------------------------------------------------------------------------------------------
130 //---------------------------------------------------------------------------------------------------------------------------
133 CCPApplet::OnRun(CWnd
* pParentWnd
)
136 CWnd
* pWnd
= (CWnd
*) m_uiClass
->CreateObject();
140 lResult
= ERROR_SUCCESS
;
142 if ( pWnd
->IsKindOf( RUNTIME_CLASS( CPropertySheet
) ) )
144 CPropertySheet
* pSheet
= (CPropertySheet
*) pWnd
;
146 pSheet
->Construct(m_name
, pParentWnd
, m_pageNumber
);
152 check( pWnd
->IsKindOf( RUNTIME_CLASS( CDialog
) ) );
154 CDialog
* pDialog
= (CDialog
*) pWnd
;
166 //---------------------------------------------------------------------------------------------------------------------------
167 // CCPApplet::OnInquire
168 //---------------------------------------------------------------------------------------------------------------------------
171 CCPApplet::OnInquire(CPLINFO
* pInfo
)
173 pInfo
->idIcon
= m_resourceId
;
174 pInfo
->idName
= m_resourceId
;
175 pInfo
->idInfo
= m_descId
;
176 pInfo
->lData
= reinterpret_cast<LONG
>(this);
182 //---------------------------------------------------------------------------------------------------------------------------
183 // CCPApplet::OnNewInquire
184 //---------------------------------------------------------------------------------------------------------------------------
187 CCPApplet::OnNewInquire(NEWCPLINFO
* pInfo
)
189 DEBUG_UNUSED( pInfo
);
195 //---------------------------------------------------------------------------------------------------------------------------
196 // CCPApplet::OnSelect
197 //---------------------------------------------------------------------------------------------------------------------------
200 CCPApplet::OnSelect()
206 //---------------------------------------------------------------------------------------------------------------------------
208 //---------------------------------------------------------------------------------------------------------------------------
217 IMPLEMENT_DYNAMIC(CCPApp
, CWinApp
);
219 //---------------------------------------------------------------------------------------------------------------------------
221 //---------------------------------------------------------------------------------------------------------------------------
225 debug_initialize( kDebugOutputTypeWindowsEventLog
, "DNS-SD Control Panel", GetModuleHandle( NULL
) );
226 debug_set_property( kDebugPropertyTagPrintLevel
, kDebugLevelInfo
);
230 //---------------------------------------------------------------------------------------------------------------------------
232 //---------------------------------------------------------------------------------------------------------------------------
236 while ( !m_applets
.IsEmpty() )
238 delete m_applets
.RemoveHead();
243 //---------------------------------------------------------------------------------------------------------------------------
245 //---------------------------------------------------------------------------------------------------------------------------
248 CCPApp::AddApplet( CCPApplet
* applet
)
252 m_applets
.AddTail( applet
);
256 //---------------------------------------------------------------------------------------------------------------------------
258 //---------------------------------------------------------------------------------------------------------------------------
267 applet
= new CCPApplet( IDR_APPLET
, IDS_APPLET_DESCRIPTION
, RUNTIME_CLASS( CConfigPropertySheet
) );
274 require_action( applet
, exit
, kNoMemoryErr
);
280 return m_applets
.GetCount();
284 //---------------------------------------------------------------------------------------------------------------------------
286 //---------------------------------------------------------------------------------------------------------------------------
295 //---------------------------------------------------------------------------------------------------------------------------
297 //---------------------------------------------------------------------------------------------------------------------------
300 CCPApp::OnCplMsg(HWND hWndCPl
, UINT uMsg
, LONG lParam1
, LONG lParam2
)
320 lResult
= m_applets
.GetCount();
326 POSITION pos
= m_applets
.FindIndex( lParam1
);
329 CCPApplet
* applet
= m_applets
.GetAt( pos
);
336 LPCPLINFO pInfo
= reinterpret_cast<LPCPLINFO
>(lParam2
);
337 lResult
= applet
->OnInquire(pInfo
);
343 LPNEWCPLINFO pInfo
= reinterpret_cast<LPNEWCPLINFO
>(lParam2
);
344 lResult
= applet
->OnNewInquire(pInfo
);
348 case CPL_STARTWPARMS
:
350 CWnd
* pParentWnd
= CWnd::FromHandle(hWndCPl
);
351 LPCTSTR lpszExtra
= reinterpret_cast<LPCTSTR
>(lParam2
);
352 lResult
= applet
->OnStartParms(pParentWnd
, lpszExtra
);
358 CWnd
* pParentWnd
= CWnd::FromHandle(hWndCPl
);
359 lResult
= applet
->OnRun(pParentWnd
);
365 lResult
= applet
->OnSelect();
371 lResult
= applet
->OnStop();
377 // TRACE(_T("Warning, Received an unknown control panel message:%d\n"), uMsg);