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.4 2005/10/05 20:46:50 herscher
27 <rdar://problem/4192011> Move Wide-Area preferences to another part of the registry so they don't removed during an update-install.
29 Revision 1.3 2005/03/07 18:27:42 shersche
30 <rdar://problem/4037940> Fix problem when ControlPanel commits changes to the browse domain list
32 Revision 1.2 2005/03/03 19:55:22 shersche
33 <rdar://problem/4034481> ControlPanel source code isn't saving CVS log info
38 #include "ThirdPage.h"
41 #include "ConfigPropertySheet.h"
42 #include "SharedSecret.h"
44 #include <WinServices.h>
46 #define MAX_KEY_LENGTH 255
49 IMPLEMENT_DYNCREATE(CThirdPage
, CPropertyPage
)
52 //---------------------------------------------------------------------------------------------------------------------------
53 // CThirdPage::CThirdPage
54 //---------------------------------------------------------------------------------------------------------------------------
56 CThirdPage::CThirdPage()
58 CPropertyPage(CThirdPage::IDD
)
60 //{{AFX_DATA_INIT(CThirdPage)
67 //---------------------------------------------------------------------------------------------------------------------------
68 // CThirdPage::~CThirdPage
69 //---------------------------------------------------------------------------------------------------------------------------
71 CThirdPage::~CThirdPage()
76 //---------------------------------------------------------------------------------------------------------------------------
77 // CThirdPage::DoDataExchange
78 //---------------------------------------------------------------------------------------------------------------------------
80 void CThirdPage::DoDataExchange(CDataExchange
* pDX
)
82 CPropertyPage::DoDataExchange(pDX
);
83 //{{AFX_DATA_MAP(CThirdPage)
85 DDX_Control(pDX
, IDC_BROWSE_LIST
, m_browseListCtrl
);
86 DDX_Control(pDX
, IDC_REMOVE_BROWSE_DOMAIN
, m_removeButton
);
89 BEGIN_MESSAGE_MAP(CThirdPage
, CPropertyPage
)
90 //{{AFX_MSG_MAP(CThirdPage)
92 ON_BN_CLICKED(IDC_ADD_BROWSE_DOMAIN
, OnBnClickedAddBrowseDomain
)
93 ON_BN_CLICKED(IDC_REMOVE_BROWSE_DOMAIN
, OnBnClickedRemoveBrowseDomain
)
94 ON_NOTIFY(LVN_ITEMCHANGED
, IDC_BROWSE_LIST
, OnLvnItemchangedBrowseList
)
98 //---------------------------------------------------------------------------------------------------------------------------
99 // CThirdPage::SetModified
100 //---------------------------------------------------------------------------------------------------------------------------
102 void CThirdPage::SetModified( BOOL bChanged
)
104 m_modified
= bChanged
;
106 CPropertyPage::SetModified( bChanged
);
110 //---------------------------------------------------------------------------------------------------------------------------
111 // CThirdPage::OnSetActive
112 //---------------------------------------------------------------------------------------------------------------------------
115 CThirdPage::OnSetActive()
117 CConfigPropertySheet
* psheet
;
123 TCHAR subKeyName
[MAX_KEY_LENGTH
];
129 BOOL b
= CPropertyPage::OnSetActive();
131 psheet
= reinterpret_cast<CConfigPropertySheet
*>(GetParent());
132 require_quiet( psheet
, exit
);
138 m_browseListCtrl
.SetExtendedStyle((m_browseListCtrl
.GetStyle() & (~LVS_EX_GRIDLINES
))|LVS_EX_CHECKBOXES
| LVS_EX_FULLROWSELECT
);
140 m_browseListCtrl
.InsertColumn(0, L
"", LVCFMT_LEFT
, 20 );
141 m_browseListCtrl
.InsertColumn(1, L
"", LVCFMT_LEFT
, 345);
146 m_initialized
= false;
148 // Clear out what's there
150 m_browseListCtrl
.DeleteAllItems();
152 // Now populate the browse domain box
154 err
= RegCreateKey( HKEY_LOCAL_MACHINE
, kServiceParametersNode L
"\\DynDNS\\Setup\\" kServiceDynDNSBrowseDomains
, &key
);
155 require_noerr( err
, exit
);
157 // Get information about this node
159 err
= RegQueryInfoKey( key
, NULL
, NULL
, NULL
, &cSubKeys
, &cbMaxSubKey
, &cchMaxClass
, NULL
, NULL
, NULL
, NULL
, NULL
);
160 require_noerr( err
, exit
);
162 for ( i
= 0; i
< cSubKeys
; i
++)
164 dwSize
= MAX_KEY_LENGTH
;
166 err
= RegEnumKeyEx( key
, i
, subKeyName
, &dwSize
, NULL
, NULL
, NULL
, NULL
);
167 require_noerr( err
, exit
);
169 err
= RegOpenKey( key
, subKeyName
, &subKey
);
170 require_noerr( err
, exit
);
172 dwSize
= sizeof( DWORD
);
173 err
= RegQueryValueEx( subKey
, L
"Enabled", NULL
, NULL
, (LPBYTE
) &enabled
, &dwSize
);
174 require_noerr( err
, exit
);
176 nIndex
= m_browseListCtrl
.InsertItem( m_browseListCtrl
.GetItemCount(), L
"");
177 m_browseListCtrl
.SetItemText( nIndex
, 1, subKeyName
);
178 m_browseListCtrl
.SetCheck( nIndex
, enabled
);
180 RegCloseKey( subKey
);
184 m_browseListCtrl
.SortItems( SortFunc
, (DWORD_PTR
) this );
186 m_removeButton
.EnableWindow( FALSE
);
192 RegCloseKey( subKey
);
200 m_initialized
= true;
207 //---------------------------------------------------------------------------------------------------------------------------
209 //---------------------------------------------------------------------------------------------------------------------------
222 //---------------------------------------------------------------------------------------------------------------------------
223 // CThirdPage::Commit
224 //---------------------------------------------------------------------------------------------------------------------------
231 TCHAR subKeyName
[MAX_KEY_LENGTH
];
239 err
= RegCreateKey( HKEY_LOCAL_MACHINE
, kServiceParametersNode L
"\\DynDNS\\Setup\\" kServiceDynDNSBrowseDomains
, &key
);
240 require_noerr( err
, exit
);
242 // First, remove all the entries that are there
244 err
= RegQueryInfoKey( key
, NULL
, NULL
, NULL
, &cSubKeys
, &cbMaxSubKey
, &cchMaxClass
, NULL
, NULL
, NULL
, NULL
, NULL
);
245 require_noerr( err
, exit
);
247 for ( i
= 0; i
< (int) cSubKeys
; i
++ )
249 dwSize
= MAX_KEY_LENGTH
;
251 err
= RegEnumKeyEx( key
, 0, subKeyName
, &dwSize
, NULL
, NULL
, NULL
, NULL
);
252 require_noerr( err
, exit
);
254 err
= RegDeleteKey( key
, subKeyName
);
255 require_noerr( err
, exit
);
260 for ( i
= 0; i
< m_browseListCtrl
.GetItemCount(); i
++ )
262 DWORD enabled
= (DWORD
) m_browseListCtrl
.GetCheck( i
);
264 err
= RegCreateKey( key
, m_browseListCtrl
.GetItemText( i
, 1 ), &subKey
);
265 require_noerr( err
, exit
);
267 err
= RegSetValueEx( subKey
, L
"Enabled", NULL
, REG_DWORD
, (LPBYTE
) &enabled
, sizeof( enabled
) );
268 require_noerr( err
, exit
);
270 RegCloseKey( subKey
);
278 RegCloseKey( subKey
);
289 //---------------------------------------------------------------------------------------------------------------------------
290 // CThirdPage::OnBnClickedAddBrowseDomain
291 //---------------------------------------------------------------------------------------------------------------------------
294 CThirdPage::OnBnClickedAddBrowseDomain()
296 CAddBrowseDomain
dlg( GetParent() );
298 if ( ( dlg
.DoModal() == IDOK
) && ( dlg
.m_text
.GetLength() > 0 ) )
302 nIndex
= m_browseListCtrl
.InsertItem( m_browseListCtrl
.GetItemCount(), L
"");
303 m_browseListCtrl
.SetItemText( nIndex
, 1, dlg
.m_text
);
304 m_browseListCtrl
.SetCheck( nIndex
, 1 );
306 m_browseListCtrl
.SortItems( SortFunc
, (DWORD_PTR
) this );
308 m_browseListCtrl
.Invalidate();
315 //---------------------------------------------------------------------------------------------------------------------------
316 // CThirdPage::OnBnClickedRemoveBrowseDomain
317 //---------------------------------------------------------------------------------------------------------------------------
320 CThirdPage::OnBnClickedRemoveBrowseDomain()
322 UINT selectedCount
= m_browseListCtrl
.GetSelectedCount();
326 // Update all of the selected items.
328 for ( i
= 0; i
< selectedCount
; i
++ )
330 nItem
= m_browseListCtrl
.GetNextItem( -1, LVNI_SELECTED
);
331 check( nItem
!= -1 );
333 m_browseListCtrl
.DeleteItem( nItem
);
338 m_removeButton
.EnableWindow( FALSE
);
343 CThirdPage::OnLvnItemchangedBrowseList(NMHDR
*pNMHDR
, LRESULT
*pResult
)
345 if ( m_browseListCtrl
.GetSelectedCount() )
347 m_removeButton
.EnableWindow( TRUE
);
352 NM_LISTVIEW
* pNMListView
= (NM_LISTVIEW
*)pNMHDR
;
354 BOOL bPrevState
= (BOOL
) ( ( ( pNMListView
->uOldState
& LVIS_STATEIMAGEMASK
) >> 12 ) - 1 );
356 if ( bPrevState
< 0 )
362 BOOL bChecked
= ( BOOL
) ( ( ( pNMListView
->uNewState
& LVIS_STATEIMAGEMASK
) >> 12) - 1 );
369 if ( bPrevState
!= bChecked
)
381 CThirdPage::SortFunc(LPARAM lParam1
, LPARAM lParam2
, LPARAM lParamSort
)
387 CThirdPage
* self
= reinterpret_cast<CThirdPage
*>( lParamSort
);
388 require_quiet( self
, exit
);
390 str1
= self
->m_browseListCtrl
.GetItemText( (int) lParam1
, 1 );
391 str2
= self
->m_browseListCtrl
.GetItemText( (int) lParam2
, 1 );
393 ret
= str1
.Compare( str2
);
401 // CAddBrowseDomain dialog
403 IMPLEMENT_DYNAMIC(CAddBrowseDomain
, CDialog
)
404 CAddBrowseDomain::CAddBrowseDomain(CWnd
* pParent
/*=NULL*/)
405 : CDialog(CAddBrowseDomain::IDD
, pParent
)
409 CAddBrowseDomain::~CAddBrowseDomain()
413 void CAddBrowseDomain::DoDataExchange(CDataExchange
* pDX
)
415 CDialog::DoDataExchange(pDX
);
416 DDX_Control(pDX
, IDC_COMBO1
, m_comboBox
);
421 CAddBrowseDomain::OnInitDialog()
423 CConfigPropertySheet
* psheet
;
424 CConfigPropertySheet::StringList::iterator it
;
426 BOOL b
= CDialog::OnInitDialog();
428 psheet
= reinterpret_cast<CConfigPropertySheet
*>(GetParent());
429 require_quiet( psheet
, exit
);
431 for ( it
= psheet
->m_browseDomains
.begin(); it
!= psheet
->m_browseDomains
.end(); it
++ )
435 if ( m_comboBox
.FindStringExact( -1, *it
) == CB_ERR
)
437 m_comboBox
.AddString( *it
);
448 CAddBrowseDomain::OnOK()
450 m_comboBox
.GetWindowText( m_text
);
457 BEGIN_MESSAGE_MAP(CAddBrowseDomain
, CDialog
)