2 * Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
23 Change History (most recent first):
25 $Log: ThirdPage.cpp,v $
26 Revision 1.3 2005/03/07 18:27:42 shersche
27 <rdar://problem/4037940> Fix problem when ControlPanel commits changes to the browse domain list
29 Revision 1.2 2005/03/03 19:55:22 shersche
30 <rdar://problem/4034481> ControlPanel source code isn't saving CVS log info
35 #include "ThirdPage.h"
38 #include "ConfigPropertySheet.h"
39 #include "SharedSecret.h"
41 #include <WinServices.h>
43 #define MAX_KEY_LENGTH 255
46 IMPLEMENT_DYNCREATE(CThirdPage
, CPropertyPage
)
49 //---------------------------------------------------------------------------------------------------------------------------
50 // CThirdPage::CThirdPage
51 //---------------------------------------------------------------------------------------------------------------------------
53 CThirdPage::CThirdPage()
55 CPropertyPage(CThirdPage::IDD
)
57 //{{AFX_DATA_INIT(CThirdPage)
64 //---------------------------------------------------------------------------------------------------------------------------
65 // CThirdPage::~CThirdPage
66 //---------------------------------------------------------------------------------------------------------------------------
68 CThirdPage::~CThirdPage()
73 //---------------------------------------------------------------------------------------------------------------------------
74 // CThirdPage::DoDataExchange
75 //---------------------------------------------------------------------------------------------------------------------------
77 void CThirdPage::DoDataExchange(CDataExchange
* pDX
)
79 CPropertyPage::DoDataExchange(pDX
);
80 //{{AFX_DATA_MAP(CThirdPage)
82 DDX_Control(pDX
, IDC_BROWSE_LIST
, m_browseListCtrl
);
83 DDX_Control(pDX
, IDC_REMOVE_BROWSE_DOMAIN
, m_removeButton
);
86 BEGIN_MESSAGE_MAP(CThirdPage
, CPropertyPage
)
87 //{{AFX_MSG_MAP(CThirdPage)
89 ON_BN_CLICKED(IDC_ADD_BROWSE_DOMAIN
, OnBnClickedAddBrowseDomain
)
90 ON_BN_CLICKED(IDC_REMOVE_BROWSE_DOMAIN
, OnBnClickedRemoveBrowseDomain
)
91 ON_NOTIFY(LVN_ITEMCHANGED
, IDC_BROWSE_LIST
, OnLvnItemchangedBrowseList
)
95 //---------------------------------------------------------------------------------------------------------------------------
96 // CThirdPage::SetModified
97 //---------------------------------------------------------------------------------------------------------------------------
99 void CThirdPage::SetModified( BOOL bChanged
)
101 m_modified
= bChanged
;
103 CPropertyPage::SetModified( bChanged
);
107 //---------------------------------------------------------------------------------------------------------------------------
108 // CThirdPage::OnSetActive
109 //---------------------------------------------------------------------------------------------------------------------------
112 CThirdPage::OnSetActive()
114 CConfigPropertySheet
* psheet
;
120 TCHAR subKeyName
[MAX_KEY_LENGTH
];
126 BOOL b
= CPropertyPage::OnSetActive();
128 psheet
= reinterpret_cast<CConfigPropertySheet
*>(GetParent());
129 require_quiet( psheet
, exit
);
135 m_browseListCtrl
.SetExtendedStyle((m_browseListCtrl
.GetStyle() & (~LVS_EX_GRIDLINES
))|LVS_EX_CHECKBOXES
| LVS_EX_FULLROWSELECT
);
137 m_browseListCtrl
.InsertColumn(0, L
"", LVCFMT_LEFT
, 20 );
138 m_browseListCtrl
.InsertColumn(1, L
"", LVCFMT_LEFT
, 345);
143 m_initialized
= false;
145 // Clear out what's there
147 m_browseListCtrl
.DeleteAllItems();
149 // Now populate the browse domain box
151 err
= RegCreateKey( HKEY_LOCAL_MACHINE
, L
"SYSTEM\\CurrentControlSet\\Services\\" kServiceName L
"\\Parameters\\DynDNS\\Setup\\" kServiceDynDNSBrowseDomains
, &key
);
152 require_noerr( err
, exit
);
154 // Get information about this node
156 err
= RegQueryInfoKey( key
, NULL
, NULL
, NULL
, &cSubKeys
, &cbMaxSubKey
, &cchMaxClass
, NULL
, NULL
, NULL
, NULL
, NULL
);
157 require_noerr( err
, exit
);
159 for ( i
= 0; i
< cSubKeys
; i
++)
161 dwSize
= MAX_KEY_LENGTH
;
163 err
= RegEnumKeyEx( key
, i
, subKeyName
, &dwSize
, NULL
, NULL
, NULL
, NULL
);
164 require_noerr( err
, exit
);
166 err
= RegOpenKey( key
, subKeyName
, &subKey
);
167 require_noerr( err
, exit
);
169 dwSize
= sizeof( DWORD
);
170 err
= RegQueryValueEx( subKey
, L
"Enabled", NULL
, NULL
, (LPBYTE
) &enabled
, &dwSize
);
171 require_noerr( err
, exit
);
173 nIndex
= m_browseListCtrl
.InsertItem( m_browseListCtrl
.GetItemCount(), L
"");
174 m_browseListCtrl
.SetItemText( nIndex
, 1, subKeyName
);
175 m_browseListCtrl
.SetCheck( nIndex
, enabled
);
177 RegCloseKey( subKey
);
181 m_browseListCtrl
.SortItems( SortFunc
, (DWORD_PTR
) this );
183 m_removeButton
.EnableWindow( FALSE
);
189 RegCloseKey( subKey
);
197 m_initialized
= true;
204 //---------------------------------------------------------------------------------------------------------------------------
206 //---------------------------------------------------------------------------------------------------------------------------
219 //---------------------------------------------------------------------------------------------------------------------------
220 // CThirdPage::Commit
221 //---------------------------------------------------------------------------------------------------------------------------
228 TCHAR subKeyName
[MAX_KEY_LENGTH
];
236 err
= RegCreateKey( HKEY_LOCAL_MACHINE
, L
"SYSTEM\\CurrentControlSet\\Services\\" kServiceName L
"\\Parameters\\DynDNS\\Setup\\" kServiceDynDNSBrowseDomains
, &key
);
237 require_noerr( err
, exit
);
239 // First, remove all the entries that are there
241 err
= RegQueryInfoKey( key
, NULL
, NULL
, NULL
, &cSubKeys
, &cbMaxSubKey
, &cchMaxClass
, NULL
, NULL
, NULL
, NULL
, NULL
);
242 require_noerr( err
, exit
);
244 for ( i
= 0; i
< (int) cSubKeys
; i
++ )
246 dwSize
= MAX_KEY_LENGTH
;
248 err
= RegEnumKeyEx( key
, 0, subKeyName
, &dwSize
, NULL
, NULL
, NULL
, NULL
);
249 require_noerr( err
, exit
);
251 err
= RegDeleteKey( key
, subKeyName
);
252 require_noerr( err
, exit
);
257 for ( i
= 0; i
< m_browseListCtrl
.GetItemCount(); i
++ )
259 DWORD enabled
= (DWORD
) m_browseListCtrl
.GetCheck( i
);
261 err
= RegCreateKey( key
, m_browseListCtrl
.GetItemText( i
, 1 ), &subKey
);
262 require_noerr( err
, exit
);
264 err
= RegSetValueEx( subKey
, L
"Enabled", NULL
, REG_DWORD
, (LPBYTE
) &enabled
, sizeof( enabled
) );
265 require_noerr( err
, exit
);
267 RegCloseKey( subKey
);
275 RegCloseKey( subKey
);
286 //---------------------------------------------------------------------------------------------------------------------------
287 // CThirdPage::OnBnClickedAddBrowseDomain
288 //---------------------------------------------------------------------------------------------------------------------------
291 CThirdPage::OnBnClickedAddBrowseDomain()
293 CAddBrowseDomain
dlg( GetParent() );
295 if ( ( dlg
.DoModal() == IDOK
) && ( dlg
.m_text
.GetLength() > 0 ) )
299 nIndex
= m_browseListCtrl
.InsertItem( m_browseListCtrl
.GetItemCount(), L
"");
300 m_browseListCtrl
.SetItemText( nIndex
, 1, dlg
.m_text
);
301 m_browseListCtrl
.SetCheck( nIndex
, 1 );
303 m_browseListCtrl
.SortItems( SortFunc
, (DWORD_PTR
) this );
305 m_browseListCtrl
.Invalidate();
312 //---------------------------------------------------------------------------------------------------------------------------
313 // CThirdPage::OnBnClickedRemoveBrowseDomain
314 //---------------------------------------------------------------------------------------------------------------------------
317 CThirdPage::OnBnClickedRemoveBrowseDomain()
319 UINT selectedCount
= m_browseListCtrl
.GetSelectedCount();
323 // Update all of the selected items.
325 for ( i
= 0; i
< selectedCount
; i
++ )
327 nItem
= m_browseListCtrl
.GetNextItem( -1, LVNI_SELECTED
);
328 check( nItem
!= -1 );
330 m_browseListCtrl
.DeleteItem( nItem
);
335 m_removeButton
.EnableWindow( FALSE
);
340 CThirdPage::OnLvnItemchangedBrowseList(NMHDR
*pNMHDR
, LRESULT
*pResult
)
342 if ( m_browseListCtrl
.GetSelectedCount() )
344 m_removeButton
.EnableWindow( TRUE
);
349 NM_LISTVIEW
* pNMListView
= (NM_LISTVIEW
*)pNMHDR
;
351 BOOL bPrevState
= (BOOL
) ( ( ( pNMListView
->uOldState
& LVIS_STATEIMAGEMASK
) >> 12 ) - 1 );
353 if ( bPrevState
< 0 )
359 BOOL bChecked
= ( BOOL
) ( ( ( pNMListView
->uNewState
& LVIS_STATEIMAGEMASK
) >> 12) - 1 );
366 if ( bPrevState
!= bChecked
)
378 CThirdPage::SortFunc(LPARAM lParam1
, LPARAM lParam2
, LPARAM lParamSort
)
384 CThirdPage
* self
= reinterpret_cast<CThirdPage
*>( lParamSort
);
385 require_quiet( self
, exit
);
387 str1
= self
->m_browseListCtrl
.GetItemText( (int) lParam1
, 1 );
388 str2
= self
->m_browseListCtrl
.GetItemText( (int) lParam2
, 1 );
390 ret
= str1
.Compare( str2
);
398 // CAddBrowseDomain dialog
400 IMPLEMENT_DYNAMIC(CAddBrowseDomain
, CDialog
)
401 CAddBrowseDomain::CAddBrowseDomain(CWnd
* pParent
/*=NULL*/)
402 : CDialog(CAddBrowseDomain::IDD
, pParent
)
406 CAddBrowseDomain::~CAddBrowseDomain()
410 void CAddBrowseDomain::DoDataExchange(CDataExchange
* pDX
)
412 CDialog::DoDataExchange(pDX
);
413 DDX_Control(pDX
, IDC_COMBO1
, m_comboBox
);
418 CAddBrowseDomain::OnInitDialog()
420 CConfigPropertySheet
* psheet
;
421 CConfigPropertySheet::StringList::iterator it
;
423 BOOL b
= CDialog::OnInitDialog();
425 psheet
= reinterpret_cast<CConfigPropertySheet
*>(GetParent());
426 require_quiet( psheet
, exit
);
428 for ( it
= psheet
->m_browseDomains
.begin(); it
!= psheet
->m_browseDomains
.end(); it
++ )
432 if ( m_comboBox
.FindStringExact( -1, *it
) == CB_ERR
)
434 m_comboBox
.AddString( *it
);
445 CAddBrowseDomain::OnOK()
447 m_comboBox
.GetWindowText( m_text
);
454 BEGIN_MESSAGE_MAP(CAddBrowseDomain
, CDialog
)