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.
18 #include "BrowsingPage.h"
21 #include "ConfigPropertySheet.h"
23 #include <WinServices.h>
25 #define MAX_KEY_LENGTH 255
28 IMPLEMENT_DYNCREATE(CBrowsingPage
, CPropertyPage
)
31 //---------------------------------------------------------------------------------------------------------------------------
32 // CBrowsingPage::CBrowsingPage
33 //---------------------------------------------------------------------------------------------------------------------------
35 CBrowsingPage::CBrowsingPage()
37 CPropertyPage(CBrowsingPage::IDD
)
39 //{{AFX_DATA_INIT(CBrowsingPage)
46 //---------------------------------------------------------------------------------------------------------------------------
47 // CBrowsingPage::~CBrowsingPage
48 //---------------------------------------------------------------------------------------------------------------------------
50 CBrowsingPage::~CBrowsingPage()
55 //---------------------------------------------------------------------------------------------------------------------------
56 // CBrowsingPage::DoDataExchange
57 //---------------------------------------------------------------------------------------------------------------------------
59 void CBrowsingPage::DoDataExchange(CDataExchange
* pDX
)
61 CPropertyPage::DoDataExchange(pDX
);
62 //{{AFX_DATA_MAP(CBrowsingPage)
64 DDX_Control(pDX
, IDC_BROWSE_LIST
, m_browseListCtrl
);
65 DDX_Control(pDX
, IDC_REMOVE_BROWSE_DOMAIN
, m_removeButton
);
68 BEGIN_MESSAGE_MAP(CBrowsingPage
, CPropertyPage
)
69 //{{AFX_MSG_MAP(CBrowsingPage)
71 ON_BN_CLICKED(IDC_ADD_BROWSE_DOMAIN
, OnBnClickedAddBrowseDomain
)
72 ON_BN_CLICKED(IDC_REMOVE_BROWSE_DOMAIN
, OnBnClickedRemoveBrowseDomain
)
73 ON_NOTIFY(LVN_ITEMCHANGED
, IDC_BROWSE_LIST
, OnLvnItemchangedBrowseList
)
77 //---------------------------------------------------------------------------------------------------------------------------
78 // CBrowsingPage::SetModified
79 //---------------------------------------------------------------------------------------------------------------------------
81 void CBrowsingPage::SetModified( BOOL bChanged
)
83 m_modified
= bChanged
;
85 CPropertyPage::SetModified( bChanged
);
89 //---------------------------------------------------------------------------------------------------------------------------
90 // CBrowsingPage::OnSetActive
91 //---------------------------------------------------------------------------------------------------------------------------
94 CBrowsingPage::OnSetActive()
96 CConfigPropertySheet
* psheet
;
102 TCHAR subKeyName
[MAX_KEY_LENGTH
];
108 BOOL b
= CPropertyPage::OnSetActive();
110 psheet
= reinterpret_cast<CConfigPropertySheet
*>(GetParent());
111 require_quiet( psheet
, exit
);
117 m_browseListCtrl
.SetExtendedStyle((m_browseListCtrl
.GetStyle() & (~LVS_EX_GRIDLINES
))|LVS_EX_CHECKBOXES
| LVS_EX_FULLROWSELECT
);
119 m_browseListCtrl
.InsertColumn(0, L
"", LVCFMT_LEFT
, 20 );
120 m_browseListCtrl
.InsertColumn(1, L
"", LVCFMT_LEFT
, 345);
125 m_initialized
= false;
127 // Clear out what's there
129 m_browseListCtrl
.DeleteAllItems();
131 // Now populate the browse domain box
133 err
= RegCreateKeyEx( HKEY_LOCAL_MACHINE
, kServiceParametersNode L
"\\DynDNS\\Setup\\" kServiceDynDNSBrowseDomains
, 0,
134 NULL
, REG_OPTION_NON_VOLATILE
, KEY_READ
|KEY_WRITE
, NULL
, &key
, NULL
);
135 require_noerr( err
, exit
);
137 // Get information about this node
139 err
= RegQueryInfoKey( key
, NULL
, NULL
, NULL
, &cSubKeys
, &cbMaxSubKey
, &cchMaxClass
, NULL
, NULL
, NULL
, NULL
, NULL
);
140 require_noerr( err
, exit
);
142 for ( i
= 0; i
< cSubKeys
; i
++)
144 dwSize
= MAX_KEY_LENGTH
;
146 err
= RegEnumKeyEx( key
, i
, subKeyName
, &dwSize
, NULL
, NULL
, NULL
, NULL
);
147 require_noerr( err
, exit
);
149 err
= RegOpenKey( key
, subKeyName
, &subKey
);
150 require_noerr( err
, exit
);
152 dwSize
= sizeof( DWORD
);
153 err
= RegQueryValueEx( subKey
, L
"Enabled", NULL
, NULL
, (LPBYTE
) &enabled
, &dwSize
);
154 require_noerr( err
, exit
);
156 nIndex
= m_browseListCtrl
.InsertItem( m_browseListCtrl
.GetItemCount(), L
"");
157 m_browseListCtrl
.SetItemText( nIndex
, 1, subKeyName
);
158 m_browseListCtrl
.SetCheck( nIndex
, enabled
);
160 RegCloseKey( subKey
);
164 m_browseListCtrl
.SortItems( SortFunc
, (DWORD_PTR
) this );
166 m_removeButton
.EnableWindow( FALSE
);
172 RegCloseKey( subKey
);
180 m_initialized
= true;
187 //---------------------------------------------------------------------------------------------------------------------------
188 // CBrowsingPage::OnOK
189 //---------------------------------------------------------------------------------------------------------------------------
192 CBrowsingPage::OnOK()
202 //---------------------------------------------------------------------------------------------------------------------------
203 // CBrowsingPage::Commit
204 //---------------------------------------------------------------------------------------------------------------------------
207 CBrowsingPage::Commit()
211 TCHAR subKeyName
[MAX_KEY_LENGTH
];
219 err
= RegCreateKeyEx( HKEY_LOCAL_MACHINE
, kServiceParametersNode L
"\\DynDNS\\Setup\\" kServiceDynDNSBrowseDomains
, 0,
220 NULL
, REG_OPTION_NON_VOLATILE
, KEY_READ
|KEY_WRITE
, NULL
, &key
, NULL
);
221 require_noerr( err
, exit
);
223 // First, remove all the entries that are there
225 err
= RegQueryInfoKey( key
, NULL
, NULL
, NULL
, &cSubKeys
, &cbMaxSubKey
, &cchMaxClass
, NULL
, NULL
, NULL
, NULL
, NULL
);
226 require_noerr( err
, exit
);
228 for ( i
= 0; i
< (int) cSubKeys
; i
++ )
230 dwSize
= MAX_KEY_LENGTH
;
232 err
= RegEnumKeyEx( key
, 0, subKeyName
, &dwSize
, NULL
, NULL
, NULL
, NULL
);
233 require_noerr( err
, exit
);
235 err
= RegDeleteKey( key
, subKeyName
);
236 require_noerr( err
, exit
);
241 for ( i
= 0; i
< m_browseListCtrl
.GetItemCount(); i
++ )
243 DWORD enabled
= (DWORD
) m_browseListCtrl
.GetCheck( i
);
245 err
= RegCreateKeyEx( key
, m_browseListCtrl
.GetItemText( i
, 1 ), 0,
246 NULL
, REG_OPTION_NON_VOLATILE
, KEY_READ
|KEY_WRITE
, NULL
, &subKey
, NULL
);
247 require_noerr( err
, exit
);
249 err
= RegSetValueEx( subKey
, L
"Enabled", NULL
, REG_DWORD
, (LPBYTE
) &enabled
, sizeof( enabled
) );
250 require_noerr( err
, exit
);
252 RegCloseKey( subKey
);
260 RegCloseKey( subKey
);
271 //---------------------------------------------------------------------------------------------------------------------------
272 // CBrowsingPage::OnBnClickedAddBrowseDomain
273 //---------------------------------------------------------------------------------------------------------------------------
276 CBrowsingPage::OnBnClickedAddBrowseDomain()
278 CAddBrowseDomain
dlg( GetParent() );
280 if ( ( dlg
.DoModal() == IDOK
) && ( dlg
.m_text
.GetLength() > 0 ) )
284 nIndex
= m_browseListCtrl
.InsertItem( m_browseListCtrl
.GetItemCount(), L
"");
285 m_browseListCtrl
.SetItemText( nIndex
, 1, dlg
.m_text
);
286 m_browseListCtrl
.SetCheck( nIndex
, 1 );
288 m_browseListCtrl
.SortItems( SortFunc
, (DWORD_PTR
) this );
290 m_browseListCtrl
.Invalidate();
297 //---------------------------------------------------------------------------------------------------------------------------
298 // CBrowsingPage::OnBnClickedRemoveBrowseDomain
299 //---------------------------------------------------------------------------------------------------------------------------
302 CBrowsingPage::OnBnClickedRemoveBrowseDomain()
304 UINT selectedCount
= m_browseListCtrl
.GetSelectedCount();
308 // Update all of the selected items.
310 for ( i
= 0; i
< selectedCount
; i
++ )
312 nItem
= m_browseListCtrl
.GetNextItem( -1, LVNI_SELECTED
);
313 check( nItem
!= -1 );
315 m_browseListCtrl
.DeleteItem( nItem
);
320 m_removeButton
.EnableWindow( FALSE
);
325 CBrowsingPage::OnLvnItemchangedBrowseList(NMHDR
*pNMHDR
, LRESULT
*pResult
)
327 if ( m_browseListCtrl
.GetSelectedCount() )
329 m_removeButton
.EnableWindow( TRUE
);
334 NM_LISTVIEW
* pNMListView
= (NM_LISTVIEW
*)pNMHDR
;
336 BOOL bPrevState
= (BOOL
) ( ( ( pNMListView
->uOldState
& LVIS_STATEIMAGEMASK
) >> 12 ) - 1 );
338 if ( bPrevState
< 0 )
344 BOOL bChecked
= ( BOOL
) ( ( ( pNMListView
->uNewState
& LVIS_STATEIMAGEMASK
) >> 12) - 1 );
351 if ( bPrevState
!= bChecked
)
363 CBrowsingPage::SortFunc(LPARAM lParam1
, LPARAM lParam2
, LPARAM lParamSort
)
369 CBrowsingPage
* self
= reinterpret_cast<CBrowsingPage
*>( lParamSort
);
370 require_quiet( self
, exit
);
372 str1
= self
->m_browseListCtrl
.GetItemText( (int) lParam1
, 1 );
373 str2
= self
->m_browseListCtrl
.GetItemText( (int) lParam2
, 1 );
375 ret
= str1
.Compare( str2
);
383 // CAddBrowseDomain dialog
385 IMPLEMENT_DYNAMIC(CAddBrowseDomain
, CDialog
)
386 CAddBrowseDomain::CAddBrowseDomain(CWnd
* pParent
/*=NULL*/)
387 : CDialog(CAddBrowseDomain::IDD
, pParent
)
391 CAddBrowseDomain::~CAddBrowseDomain()
395 void CAddBrowseDomain::DoDataExchange(CDataExchange
* pDX
)
397 CDialog::DoDataExchange(pDX
);
398 DDX_Control(pDX
, IDC_COMBO1
, m_comboBox
);
403 CAddBrowseDomain::OnInitDialog()
405 CConfigPropertySheet
* psheet
;
406 CConfigPropertySheet::StringList::iterator it
;
408 BOOL b
= CDialog::OnInitDialog();
410 psheet
= reinterpret_cast<CConfigPropertySheet
*>(GetParent());
411 require_quiet( psheet
, exit
);
413 for ( it
= psheet
->m_browseDomains
.begin(); it
!= psheet
->m_browseDomains
.end(); it
++ )
417 if ( m_comboBox
.FindStringExact( -1, *it
) == CB_ERR
)
419 m_comboBox
.AddString( *it
);
430 CAddBrowseDomain::OnOK()
432 m_comboBox
.GetWindowText( m_text
);
439 BEGIN_MESSAGE_MAP(CAddBrowseDomain
, CDialog
)