Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1451 lines
38 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. loadrecs.cpp
  7. dialog to load records from the datbase, includes by owner
  8. and by record type.
  9. FILE HISTORY:
  10. */
  11. #include "stdafx.h"
  12. #include "winssnap.h"
  13. #include "loadrecs.h"
  14. #include "server.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. BOOL MyCreateImageList(CImageList& imgList, UINT nBitmapID, int cx, int nGrow, COLORREF crMask)
  21. {
  22. ASSERT(HIWORD(nBitmapID) == 0);
  23. HINSTANCE hInst = AfxFindResourceHandle((LPCTSTR)ULongToPtr(nBitmapID), RT_BITMAP);
  24. ASSERT(hInst != NULL);
  25. return imgList.Attach(ImageList_LoadBitmap(hInst, (LPCTSTR)ULongToPtr(nBitmapID), cx, nGrow, crMask));
  26. }
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CLoadRecords
  29. IMPLEMENT_DYNAMIC(CLoadRecords, CPropertySheet)
  30. CLoadRecords::CLoadRecords(UINT nIDCaption)
  31. :CPropertySheet(nIDCaption)
  32. {
  33. AddPage(&m_pageIpAddress);
  34. AddPage(&m_pageOwners);
  35. AddPage(&m_pageTypes);
  36. m_psh.dwFlags |= PSH_NOAPPLYNOW;
  37. m_nActivePage = 0;
  38. m_bEnableCache = FALSE;
  39. m_bCaching = FALSE;
  40. }
  41. CLoadRecords::~CLoadRecords()
  42. {
  43. }
  44. VOID CLoadRecords::ResetFiltering()
  45. {
  46. m_pageOwners.m_dwaOwnerFilter.RemoveAll();
  47. m_pageIpAddress.m_dwaIPAddrs.RemoveAll();
  48. m_pageIpAddress.m_dwaIPMasks.RemoveAll();
  49. m_pageIpAddress.m_bFilterIpAddr = FALSE;
  50. m_pageIpAddress.m_bFilterIpMask = FALSE;
  51. m_pageIpAddress.m_bFilterName = FALSE;
  52. m_pageIpAddress.m_bMatchCase = FALSE;
  53. }
  54. BEGIN_MESSAGE_MAP(CLoadRecords, CPropertySheet)
  55. //{{AFX_MSG_MAP(CLoadRecords)
  56. ON_WM_HELPINFO()
  57. //}}AFX_MSG_MAP
  58. END_MESSAGE_MAP()
  59. BOOL CLoadRecords::OnInitDialog()
  60. {
  61. CPropertySheet::OnInitDialog();
  62. m_bCaching = m_bEnableCache;
  63. SetActivePage(m_nActivePage);
  64. return TRUE;
  65. }
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CLoadRecords message handlers
  68. //
  69. extern const DWORD g_aHelpIDs_DisplayRecords_PpSheet[];
  70. BOOL CLoadRecords::OnHelpInfo(HELPINFO* pHelpInfo)
  71. {
  72. int i;
  73. DWORD dwCtrlId;
  74. if (pHelpInfo->iContextType == HELPINFO_WINDOW)
  75. {
  76. DWORD * pdwHelp = (LPDWORD)g_aHelpIDs_DisplayRecords_PpSheet;
  77. if (pdwHelp)
  78. {
  79. ::WinHelp ((HWND)pHelpInfo->hItemHandle,
  80. AfxGetApp()->m_pszHelpFilePath,
  81. HELP_WM_HELP,
  82. (ULONG_PTR)pdwHelp);
  83. }
  84. }
  85. return TRUE;
  86. }
  87. /////////////////////////////////////////////////////////////////////////////
  88. // COwnerPage dialog
  89. int CALLBACK OwnerPageCompareFunc
  90. (
  91. LPARAM lParam1,
  92. LPARAM lParam2,
  93. LPARAM lParamSort
  94. )
  95. {
  96. return ((COwnerPage *) lParamSort)->HandleSort(lParam1, lParam2);
  97. }
  98. COwnerPage::COwnerPage()
  99. : CPropertyPage(COwnerPage::IDD)
  100. {
  101. m_nSortColumn = -1;
  102. for (int i = 0; i < COLUMN_MAX; i++)
  103. {
  104. m_aSortOrder[i] = TRUE; // ascending
  105. }
  106. m_pbaDirtyFlags = NULL;
  107. m_bDirtyOwners = FALSE;
  108. //{{AFX_DATA_INIT(COwnerPage)
  109. //}}AFX_DATA_INIT
  110. }
  111. COwnerPage::~COwnerPage()
  112. {
  113. if (m_pbaDirtyFlags != NULL)
  114. delete m_pbaDirtyFlags;
  115. }
  116. DWORD COwnerPage::GetOwnerForApi()
  117. {
  118. return m_dwaOwnerFilter.GetSize() == 1 ? m_dwaOwnerFilter[0] : (DWORD)-1;
  119. }
  120. void COwnerPage::DoDataExchange(CDataExchange* pDX)
  121. {
  122. CPropertyPage::DoDataExchange(pDX);
  123. //{{AFX_DATA_MAP(COwnerPage)
  124. DDX_Control(pDX, IDC_ENABLE_CACHING, m_btnEnableCache);
  125. DDX_Control(pDX, IDC_LIST_OWNER, m_listOwner);
  126. //}}AFX_DATA_MAP
  127. }
  128. BEGIN_MESSAGE_MAP(COwnerPage, CPropertyPage)
  129. //{{AFX_MSG_MAP(COwnerPage)
  130. ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST_OWNER, OnColumnclickListOwner)
  131. ON_WM_HELPINFO()
  132. ON_BN_CLICKED(IDC_BUTTON_SELECT_ALL, OnButtonSelectAll)
  133. ON_BN_CLICKED(IDC_BUTTON_UNSELECT_ALL, OnButtonUnselectAll)
  134. ON_BN_CLICKED(IDC_BUTTON_LOCAL, OnButtonLocal)
  135. ON_BN_CLICKED(IDC_ENABLE_CACHING, OnEnableCaching)
  136. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_OWNER, OnItemchangedListOwner)
  137. //}}AFX_MSG_MAP
  138. END_MESSAGE_MAP()
  139. /////////////////////////////////////////////////////////////////////////////
  140. // COwnerPage message handlers
  141. BOOL COwnerPage::OnInitDialog()
  142. {
  143. CPropertyPage::OnInitDialog();
  144. //BOOL ftest = m_ImageList.Create(IDB_LIST_STATE, 16, 1, RGB(255, 0, 0));
  145. MyCreateImageList(m_ImageList, IDB_LIST_STATE, 16, 1, RGB(255, 0, 0));
  146. // set the list item images
  147. m_listOwner.SetImageList(NULL, LVSIL_NORMAL);
  148. m_listOwner.SetImageList(NULL, LVSIL_SMALL);
  149. m_listOwner.SetImageList(&m_ImageList, LVSIL_STATE);
  150. // fill the header informnation for the list control
  151. CString strOwner;
  152. strOwner.LoadString(IDS_OWNER);
  153. m_listOwner.InsertColumn(COLUMN_IP, strOwner, LVCFMT_LEFT, 100, 1);
  154. CString strName;
  155. strName.LoadString(IDS_NAME);
  156. m_listOwner.InsertColumn(COLUMN_NAME, strName, LVCFMT_LEFT, 95, -1);
  157. CString strID;
  158. strID.LoadString(IDS_HIGHESTID);
  159. m_listOwner.InsertColumn(COLUMN_VERSION, strID, LVCFMT_LEFT, 75, -1);
  160. m_listOwner.SetFullRowSel(TRUE);
  161. // update the UI
  162. FillOwnerInfo();
  163. return TRUE;
  164. }
  165. void
  166. COwnerPage::FillOwnerInfo()
  167. {
  168. int i;
  169. m_nChecked = 0;
  170. if (m_ServerInfoArray.GetSize() > 0)
  171. {
  172. int nDirtySize = (int)m_ServerInfoArray.GetSize();
  173. if (m_pbaDirtyFlags != NULL)
  174. delete m_pbaDirtyFlags;
  175. m_pbaDirtyFlags = new BYTE[nDirtySize];
  176. if (m_pbaDirtyFlags != NULL)
  177. RtlZeroMemory(m_pbaDirtyFlags, nDirtySize);
  178. }
  179. for (i = 0; i < m_ServerInfoArray.GetSize(); i++)
  180. {
  181. //
  182. // if this owner is deleted or doesn't have any records to show
  183. // then don't add it to the list. Owners can have an ID of 0 if they don't
  184. // have any records but were found owning an address in a 1c record in the database
  185. //
  186. if ( (m_ServerInfoArray[i].m_liVersion.QuadPart == OWNER_DELETED) ||
  187. (m_ServerInfoArray[i].m_liVersion.QuadPart == 0) )
  188. {
  189. // skip this one
  190. continue;
  191. }
  192. CString strIPAdd;
  193. ::MakeIPAddress(m_ServerInfoArray[i].m_dwIp, strIPAdd);
  194. CString strVers = GetVersionInfo(m_ServerInfoArray[i].m_liVersion.LowPart,
  195. m_ServerInfoArray[i].m_liVersion.HighPart);
  196. int nItem = m_listOwner.InsertItem(i, strIPAdd, 0);
  197. m_listOwner.SetItemText(nItem, 1, m_ServerInfoArray[i].m_strName);
  198. m_listOwner.SetItemText(nItem, 2, strVers);
  199. m_listOwner.SetItemData(nItem, i);
  200. // empty filter array means all owners should be selected
  201. if (m_dwaOwnerFilter.GetSize() == 0)
  202. {
  203. m_listOwner.SetCheck(nItem, TRUE);
  204. m_pbaDirtyFlags[i] |= 2;
  205. }
  206. else
  207. {
  208. // filter array is not empty, we check the item if it is found in the filter
  209. for (int j = (int)m_dwaOwnerFilter.GetSize()-1; j >= 0; j--)
  210. {
  211. if (m_ServerInfoArray[i].m_dwIp == m_dwaOwnerFilter[j])
  212. {
  213. m_listOwner.SetCheck(nItem, TRUE);
  214. m_pbaDirtyFlags[i] |= 2;
  215. break;
  216. }
  217. }
  218. if (j < 0)
  219. {
  220. // m_nChecked keeps a count of how many items are checked in the list.
  221. // each SetCheck() balances the counter -> ++ if an item is checked
  222. // -- if an item in unchecked. However, initially, we need to set the items
  223. // that are unchecked explicitly otherwise the checkbox doesn't show up.
  224. // this could unballance the counter if we don't correct it by incrementing
  225. // it first. Whatever we add here is decremented immediately after because
  226. // of the SetCheck(..FALSE) below.
  227. m_nChecked++;
  228. m_listOwner.SetCheck(nItem, FALSE);
  229. }
  230. }
  231. }
  232. Sort(COLUMN_IP);
  233. for (i = m_listOwner.GetItemCount()-1; i >=0; i--)
  234. {
  235. if (m_listOwner.GetCheck(i))
  236. {
  237. m_listOwner.EnsureVisible(i,FALSE);
  238. break;
  239. }
  240. }
  241. m_listOwner.SetFocus();
  242. }
  243. CString
  244. COwnerPage::GetVersionInfo(LONG lLowWord, LONG lHighWord)
  245. {
  246. CString strVersionCount;
  247. TCHAR sz[20];
  248. TCHAR *pch = sz;
  249. ::wsprintf(sz, _T("%08lX%08lX"), lHighWord, lLowWord);
  250. // Kill leading zero's
  251. while (*pch == '0')
  252. {
  253. ++pch;
  254. }
  255. // At least one digit...
  256. if (*pch == '\0')
  257. {
  258. --pch;
  259. }
  260. strVersionCount = pch;
  261. return strVersionCount;
  262. }
  263. void COwnerPage::OnOK()
  264. {
  265. int i;
  266. BOOL bAllSelected;
  267. UpdateData();
  268. // clear any previous owners in the array since
  269. // GetSelectedOwner() is copying over the new
  270. // selected owners
  271. m_dwaOwnerFilter.RemoveAll();
  272. for (i = (int)m_ServerInfoArray.GetSize()-1; i>=0; i--)
  273. {
  274. if ( (m_ServerInfoArray[i].m_liVersion.QuadPart != OWNER_DELETED) &&
  275. (m_ServerInfoArray[i].m_liVersion.QuadPart != 0) &&
  276. !(m_pbaDirtyFlags[i] & 1) )
  277. {
  278. bAllSelected = FALSE;
  279. break;
  280. }
  281. }
  282. // mark owners as dirty only if some new owners are added - removing an owner shouldn't
  283. // force the database to be reloaded in any way since the records are already there.
  284. m_bDirtyOwners = FALSE;
  285. for (i = (int)m_ServerInfoArray.GetSize()-1; i >=0; i--)
  286. {
  287. // 0 - owner was not in the list and it is not now
  288. // 1 - owner was not in the list but it is now
  289. // 2 - owner was in the list and it is not now
  290. // 3 - owner was in the list and it is now
  291. if (!m_bDirtyOwners && m_pbaDirtyFlags[i] == 1)
  292. {
  293. m_bDirtyOwners = TRUE;
  294. }
  295. if (!bAllSelected && (m_pbaDirtyFlags[i] & 1))
  296. {
  297. m_dwaOwnerFilter.Add(m_ServerInfoArray[i].m_dwIp);
  298. }
  299. }
  300. CPropertyPage::OnOK();
  301. }
  302. void COwnerPage::Sort(int nCol)
  303. {
  304. if (m_nSortColumn == nCol)
  305. {
  306. // if the user is clicking the same column again, reverse the sort order
  307. m_aSortOrder[nCol] = m_aSortOrder[nCol] ? FALSE : TRUE;
  308. }
  309. else
  310. {
  311. m_nSortColumn = nCol;
  312. }
  313. m_listOwner.SortItems(OwnerPageCompareFunc, (LPARAM) this);
  314. }
  315. int COwnerPage::HandleSort(LPARAM lParam1, LPARAM lParam2)
  316. {
  317. int nCompare = 0;
  318. switch (m_nSortColumn)
  319. {
  320. case COLUMN_IP:
  321. {
  322. DWORD dwIp1 = m_ServerInfoArray.GetAt((int) lParam1).m_dwIp;
  323. DWORD dwIp2 = m_ServerInfoArray.GetAt((int) lParam2).m_dwIp;
  324. if (dwIp1 > dwIp2)
  325. nCompare = 1;
  326. else
  327. if (dwIp1 < dwIp2)
  328. nCompare = -1;
  329. }
  330. break;
  331. case COLUMN_NAME:
  332. {
  333. CString strName1 = m_ServerInfoArray[(int) lParam1].m_strName;
  334. CString strName2 = m_ServerInfoArray[(int) lParam2].m_strName;
  335. nCompare = strName1.CompareNoCase(strName2);
  336. }
  337. break;
  338. case COLUMN_VERSION:
  339. {
  340. LARGE_INTEGER li1, li2;
  341. li1.QuadPart = m_ServerInfoArray.GetAt((int) lParam1).m_liVersion.QuadPart;
  342. li2.QuadPart = m_ServerInfoArray.GetAt((int) lParam2).m_liVersion.QuadPart;
  343. if (li1.QuadPart > li2.QuadPart)
  344. nCompare = 1;
  345. else
  346. if (li1.QuadPart < li2.QuadPart)
  347. nCompare = -1;
  348. }
  349. break;
  350. }
  351. if (m_aSortOrder[m_nSortColumn] == FALSE)
  352. {
  353. // descending
  354. return -nCompare;
  355. }
  356. else
  357. {
  358. // ascending
  359. return nCompare;
  360. }
  361. }
  362. void COwnerPage::OnColumnclickListOwner(NMHDR* pNMHDR, LRESULT* pResult)
  363. {
  364. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  365. // sort depending on what column was clicked;
  366. Sort(pNMListView->iSubItem);
  367. *pResult = 0;
  368. }
  369. BOOL COwnerPage::OnHelpInfo(HELPINFO* pHelpInfo)
  370. {
  371. int i;
  372. DWORD dwCtrlId;
  373. if (pHelpInfo->iContextType == HELPINFO_WINDOW)
  374. {
  375. DWORD * pdwHelp = GetHelpMap();
  376. if (pdwHelp)
  377. {
  378. ::WinHelp ((HWND)pHelpInfo->hItemHandle,
  379. AfxGetApp()->m_pszHelpFilePath,
  380. HELP_WM_HELP,
  381. (ULONG_PTR)pdwHelp);
  382. }
  383. }
  384. return TRUE;
  385. }
  386. void COwnerPage::OnButtonLocal()
  387. {
  388. int iLocal = 0;
  389. for (int i = 0; i < m_listOwner.GetItemCount(); i++)
  390. {
  391. // item data has the owner id and the local server always
  392. // has the owner id = 0
  393. if ((DWORD)m_listOwner.GetItemData(i) == 0)
  394. iLocal = i;
  395. m_listOwner.SetCheck(i, (DWORD)m_listOwner.GetItemData(i) == 0);
  396. }
  397. m_listOwner.EnsureVisible(iLocal, FALSE);
  398. }
  399. void COwnerPage::OnButtonSelectAll()
  400. {
  401. for (int i = 0; i < m_listOwner.GetItemCount(); i++)
  402. {
  403. m_listOwner.SetCheck(i, TRUE);
  404. }
  405. }
  406. void COwnerPage::OnButtonUnselectAll()
  407. {
  408. for (int i = 0; i < m_listOwner.GetItemCount(); i++)
  409. {
  410. m_listOwner.SetCheck(i, FALSE);
  411. }
  412. }
  413. BOOL COwnerPage::OnKillActive()
  414. {
  415. int i;
  416. for (i = m_listOwner.GetItemCount()-1; i >=0 ; i--)
  417. {
  418. if (m_listOwner.GetCheck(i) == TRUE)
  419. break;
  420. }
  421. if (i<0)
  422. {
  423. // tell the user to select at least one name type to display
  424. WinsMessageBox(IDS_ERR_NO_OWNER_SPECIFIED);
  425. PropSheet_SetCurSel(GetSafeHwnd(), NULL, 0);
  426. m_listOwner.SetFocus();
  427. return FALSE;
  428. }
  429. return CPropertyPage::OnKillActive();
  430. }
  431. BOOL COwnerPage::OnSetActive()
  432. {
  433. CLoadRecords *pParent = (CLoadRecords *)GetParent();
  434. m_btnEnableCache.SetCheck(pParent->m_bCaching);
  435. return CPropertyPage::OnSetActive();
  436. }
  437. void COwnerPage::OnEnableCaching()
  438. {
  439. CLoadRecords *pParent = (CLoadRecords *)GetParent();
  440. pParent->m_bCaching = (m_btnEnableCache.GetCheck() == 1);
  441. }
  442. void COwnerPage::OnItemchangedListOwner(NMHDR* pNMHDR, LRESULT* pResult)
  443. {
  444. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  445. BOOL bInc;
  446. // if the checkbox isn't changed we don't care
  447. if ( pNMListView->uChanged & LVIF_STATE &&
  448. (pNMListView->uOldState & LVIS_STATEIMAGEMASK) != (pNMListView->uNewState & LVIS_STATEIMAGEMASK))
  449. {
  450. CLoadRecords *pParent = (CLoadRecords *)GetParent();
  451. if ((pNMListView->uNewState & INDEXTOSTATEIMAGEMASK(2)) != 0)
  452. {
  453. m_pbaDirtyFlags[pNMListView->lParam] |= 1;
  454. m_nChecked++;
  455. bInc = TRUE;
  456. }
  457. else
  458. {
  459. m_pbaDirtyFlags[pNMListView->lParam] &= ~1;
  460. m_nChecked--;
  461. bInc = FALSE;
  462. }
  463. }
  464. *pResult = 0;
  465. }
  466. /////////////////////////////////////////////////////////////////////////////
  467. // CFilterPage dialog
  468. int CALLBACK FilterPageCompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
  469. {
  470. if (lParam1 < lParam2)
  471. return -1;
  472. else
  473. if (lParam1 > lParam2)
  474. return 1;
  475. else
  476. return 0;
  477. }
  478. CFilterPage::CFilterPage()
  479. : CPropertyPage(CFilterPage::IDD)
  480. {
  481. //{{AFX_DATA_INIT(CFilterPage)
  482. //}}AFX_DATA_INIT
  483. m_bDirtyTypes = FALSE;
  484. m_pbaDirtyFlags = NULL;
  485. m_nDirtyFlags = 0;
  486. }
  487. CFilterPage::~CFilterPage()
  488. {
  489. if (m_pbaDirtyFlags != NULL)
  490. delete m_pbaDirtyFlags;
  491. }
  492. void CFilterPage::DoDataExchange(CDataExchange* pDX)
  493. {
  494. CPropertyPage::DoDataExchange(pDX);
  495. //{{AFX_DATA_MAP(CFilterPage)
  496. DDX_Control(pDX, IDC_ENABLE_CACHING, m_btnEnableCache);
  497. DDX_Control(pDX, IDC_BUTTON_DELETE_TYPE, m_buttonDelete);
  498. DDX_Control(pDX, IDC_BUTTON_MODIFY_TYPE, m_buttonModify);
  499. DDX_Control(pDX, IDC_LIST1, m_listType);
  500. //}}AFX_DATA_MAP
  501. }
  502. BEGIN_MESSAGE_MAP(CFilterPage, CPropertyPage)
  503. //{{AFX_MSG_MAP(CFilterPage)
  504. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, OnItemchangedList1)
  505. ON_BN_CLICKED(IDC_BUTTON_ADD_TYPE, OnButtonAddType)
  506. ON_BN_CLICKED(IDC_BUTTON_MODIFY_TYPE, OnButtonModifyType)
  507. ON_BN_CLICKED(IDC_BUTTON_DELETE_TYPE, OnButtonDelete)
  508. ON_WM_HELPINFO()
  509. ON_BN_CLICKED(IDC_BUTTON_SELECT_ALL, OnButtonSelectAll)
  510. ON_BN_CLICKED(IDC_BUTTON_UNSELECT_ALL, OnButtonUnselectAll)
  511. ON_BN_CLICKED(IDC_ENABLE_CACHING, OnEnableCaching)
  512. //}}AFX_MSG_MAP
  513. END_MESSAGE_MAP()
  514. /////////////////////////////////////////////////////////////////////////////
  515. // CFilterPage message handlers
  516. BOOL CFilterPage::OnInitDialog()
  517. {
  518. CPropertyPage::OnInitDialog();
  519. //BOOL ftest = m_ImageList.Create(IDB_LIST_STATE, 16, 1, RGB(255, 0, 0));
  520. MyCreateImageList(m_ImageList, IDB_LIST_STATE, 16, 1, RGB(255, 0, 0));
  521. m_listType.SetImageList(NULL, LVSIL_NORMAL);
  522. m_listType.SetImageList(NULL, LVSIL_SMALL);
  523. m_listType.SetImageList(&m_ImageList, LVSIL_STATE);
  524. m_listType.InsertColumn(0, _T("Test"), LVCFMT_LEFT, 250);
  525. m_buttonModify.EnableWindow(FALSE);
  526. m_buttonDelete.EnableWindow(FALSE);
  527. FillTypeInfo();
  528. m_nDirtyFlags = (UINT)m_arrayTypeFilter.GetSize();
  529. if (m_pbaDirtyFlags != NULL)
  530. delete m_pbaDirtyFlags;
  531. m_pbaDirtyFlags = new tDirtyFlags[m_nDirtyFlags];
  532. if ( m_pbaDirtyFlags != NULL)
  533. {
  534. RtlZeroMemory(m_pbaDirtyFlags, m_nDirtyFlags*sizeof(tDirtyFlags));
  535. for (UINT i = 0; i<m_nDirtyFlags; i++)
  536. {
  537. m_pbaDirtyFlags[i].dwType = m_arrayTypeFilter[i].dwType;
  538. if (m_arrayTypeFilter[i].fShow)
  539. {
  540. m_pbaDirtyFlags[i].bFlags = 2;
  541. }
  542. }
  543. }
  544. else
  545. {
  546. m_nDirtyFlags = 0;
  547. }
  548. return TRUE;
  549. }
  550. void CFilterPage::OnOK()
  551. {
  552. if (m_pbaDirtyFlags == NULL)
  553. {
  554. m_bDirtyTypes = TRUE;
  555. }
  556. else
  557. {
  558. int i,j;
  559. m_bDirtyTypes = FALSE;
  560. for (i = (int)m_arrayTypeFilter.GetSize()-1; i>=0; i--)
  561. {
  562. for (j = m_nDirtyFlags-1; j>=0; j--)
  563. {
  564. if (m_arrayTypeFilter[i].dwType == m_pbaDirtyFlags[j].dwType)
  565. {
  566. if (m_arrayTypeFilter[i].fShow)
  567. m_pbaDirtyFlags[j].bFlags |= 1;
  568. break;
  569. }
  570. }
  571. if (j<0 && m_arrayTypeFilter[i].fShow)
  572. {
  573. m_bDirtyTypes = TRUE;
  574. break;
  575. }
  576. }
  577. for (j = m_nDirtyFlags-1; j>=0; j--)
  578. {
  579. if (m_pbaDirtyFlags[j].bFlags == 1)
  580. {
  581. m_bDirtyTypes = TRUE;
  582. break;
  583. }
  584. }
  585. }
  586. CPropertyPage::OnOK();
  587. }
  588. BOOL CFilterPage::OnKillActive()
  589. {
  590. BOOL fShowOneType = FALSE;
  591. for (int i = 0; i < m_arrayTypeFilter.GetSize(); i++)
  592. {
  593. if (m_arrayTypeFilter[i].fShow == TRUE)
  594. {
  595. fShowOneType = TRUE;
  596. break;
  597. }
  598. }
  599. if (!fShowOneType)
  600. {
  601. // tell the user to select at least one name type to display
  602. WinsMessageBox(IDS_ERR_NO_NAME_TYPE_SPECIFIED);
  603. PropSheet_SetCurSel(GetSafeHwnd(), NULL, 0);
  604. m_listType.SetFocus();
  605. return FALSE;
  606. }
  607. return CPropertyPage::OnKillActive();
  608. }
  609. BOOL CFilterPage::OnSetActive()
  610. {
  611. CLoadRecords *pParent = (CLoadRecords *)GetParent();
  612. m_btnEnableCache.SetCheck(pParent->m_bCaching);
  613. return CPropertyPage::OnSetActive();
  614. }
  615. void CFilterPage::OnEnableCaching()
  616. {
  617. CLoadRecords *pParent = (CLoadRecords *)GetParent();
  618. pParent->m_bCaching = (m_btnEnableCache.GetCheck() == 1);
  619. }
  620. void CFilterPage::OnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult)
  621. {
  622. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  623. // check to see if this item is checked
  624. BOOL bChecked = m_listType.GetCheck(pNMListView->iItem);
  625. int nIndex = pNMListView->iItem;
  626. DWORD dwType = (DWORD) m_listType.GetItemData(nIndex);
  627. // if the state isn't changing, then we don't care
  628. if ( !(pNMListView->uChanged & LVIF_STATE) )
  629. return;
  630. for (int i = 0; i < m_arrayTypeFilter.GetSize(); i++)
  631. {
  632. if (m_arrayTypeFilter[i].dwType == dwType)
  633. {
  634. m_arrayTypeFilter[i].fShow = bChecked;
  635. }
  636. }
  637. if (m_listType.IsSelected(nIndex) &&
  638. !IsDefaultType(dwType) )
  639. {
  640. m_buttonModify.EnableWindow(TRUE);
  641. m_buttonDelete.EnableWindow(TRUE);
  642. }
  643. else
  644. {
  645. m_buttonModify.EnableWindow(FALSE);
  646. m_buttonDelete.EnableWindow(FALSE);
  647. }
  648. *pResult = 0;
  649. }
  650. void CFilterPage::OnButtonAddType()
  651. {
  652. CNameTypeDlg dlgNameType;
  653. dlgNameType.m_pNameTypeMap = m_pNameTypeMap;
  654. if (dlgNameType.DoModal() == IDOK)
  655. {
  656. // add new type here
  657. HRESULT hr = m_pNameTypeMap->AddEntry(dlgNameType.m_dwId, dlgNameType.m_strDescription);
  658. if (FAILED(hr))
  659. {
  660. WinsMessageBox(WIN32_FROM_HRESULT(hr));
  661. return;
  662. }
  663. // update our array that keeps track of check state
  664. CTypeFilterInfo typeFilterInfo;
  665. typeFilterInfo.dwType = dlgNameType.m_dwId;
  666. typeFilterInfo.fShow = TRUE;
  667. m_arrayTypeFilter.Add(typeFilterInfo);
  668. // update the listbox
  669. m_listType.DeleteAllItems();
  670. FillTypeInfo();
  671. }
  672. }
  673. void CFilterPage::OnButtonModifyType()
  674. {
  675. CNameTypeDlg dlgNameType;
  676. int nSelected;
  677. dlgNameType.m_pNameTypeMap = m_pNameTypeMap;
  678. nSelected = m_listType.GetNextItem(-1, LVNI_SELECTED);
  679. dlgNameType.m_fCreate = FALSE;
  680. dlgNameType.m_dwId = (DWORD) m_listType.GetItemData(nSelected);
  681. m_pNameTypeMap->TypeToCString(dlgNameType.m_dwId, -1, dlgNameType.m_strDescription);
  682. if (dlgNameType.DoModal() == IDOK)
  683. {
  684. // modify type here
  685. HRESULT hr = m_pNameTypeMap->ModifyEntry(dlgNameType.m_dwId, dlgNameType.m_strDescription);
  686. if (FAILED(hr))
  687. {
  688. WinsMessageBox(WIN32_FROM_HRESULT(hr));
  689. return;
  690. }
  691. // move the focus
  692. m_listType.SetFocus();
  693. SetDefID(IDOK);
  694. // update the listbox
  695. m_listType.DeleteAllItems();
  696. FillTypeInfo();
  697. }
  698. }
  699. void CFilterPage::OnButtonDelete()
  700. {
  701. HRESULT hr = hrOK;
  702. int nSelected;
  703. DWORD dwNameType;
  704. nSelected = m_listType.GetNextItem(-1, LVNI_SELECTED);
  705. dwNameType = (DWORD) m_listType.GetItemData(nSelected);
  706. // are you sure?
  707. if (AfxMessageBox(IDS_WARN_DELETE_NAME_TYPE, MB_YESNO) == IDYES)
  708. {
  709. hr = m_pNameTypeMap->RemoveEntry(dwNameType);
  710. if (SUCCEEDED(hr))
  711. {
  712. // remove from the list box
  713. m_listType.DeleteItem(nSelected);
  714. // remove from the active filters if it is in the list
  715. for (int i = 0; i < m_arrayTypeFilter.GetSize(); i++)
  716. {
  717. if (dwNameType == m_arrayTypeFilter[i].dwType)
  718. {
  719. m_arrayTypeFilter.RemoveAt(i);
  720. break;
  721. }
  722. }
  723. }
  724. else
  725. {
  726. WinsMessageBox(WIN32_FROM_HRESULT(hr));
  727. }
  728. // move the focus
  729. m_listType.SetFocus();
  730. SetDefID(IDOK);
  731. }
  732. }
  733. void
  734. CFilterPage::FillTypeInfo()
  735. {
  736. m_listType.DeleteAllItems();
  737. SPITFSNode spNode;
  738. CString strDisplay;
  739. CStringMapEntry mapEntry;
  740. int nColWidth, nColWidthTemp = 0;
  741. nColWidth = m_listType.GetColumnWidth(0);
  742. for (int i = 0; i < m_pNameTypeMap->GetSize(); i++)
  743. {
  744. mapEntry = m_pNameTypeMap->GetAt(i);
  745. // only display the default name type mapping strings, not the special
  746. // ones based on the wins type of record
  747. if (mapEntry.dwWinsType == -1)
  748. {
  749. if (mapEntry.dwNameType == NAME_TYPE_OTHER)
  750. {
  751. strDisplay.Format(_T("%s"), mapEntry.st);
  752. }
  753. else
  754. {
  755. strDisplay.Format(_T("[%02Xh] %s"), mapEntry.dwNameType, mapEntry.st);
  756. }
  757. if (m_listType.GetStringWidth(strDisplay) > nColWidthTemp)
  758. {
  759. nColWidthTemp = m_listType.GetStringWidth(strDisplay);
  760. }
  761. int nIndex = m_listType.AddItem(strDisplay, i);
  762. m_listType.SetItemData(nIndex, mapEntry.dwNameType);
  763. }
  764. }
  765. // if the strings are too long, update the column width
  766. if (nColWidthTemp > nColWidth)
  767. {
  768. m_listType.SetColumnWidth(0, nColWidthTemp + 50);
  769. }
  770. CheckItems();
  771. m_listType.SortItems(FilterPageCompareFunc, 0);
  772. }
  773. void
  774. CFilterPage::CheckItems()
  775. {
  776. int nCount = (int)m_arrayTypeFilter.GetSize();
  777. for (int i = 0; i < nCount; i++)
  778. {
  779. if (m_arrayTypeFilter[i].fShow)
  780. {
  781. DWORD dwFound = m_arrayTypeFilter[i].dwType;
  782. m_listType.CheckItem(GetIndex(dwFound));
  783. }
  784. }
  785. }
  786. void CFilterPage::OnButtonSelectAll()
  787. {
  788. for (int i = 0; i < m_listType.GetItemCount(); i++)
  789. {
  790. m_listType.SetCheck(i, TRUE);
  791. }
  792. }
  793. void CFilterPage::OnButtonUnselectAll()
  794. {
  795. for (int i = 0; i < m_listType.GetItemCount(); i++)
  796. {
  797. m_listType.SetCheck(i, FALSE);
  798. }
  799. }
  800. int
  801. CFilterPage::GetIndex(DWORD dwIndex)
  802. {
  803. int nResult = -1;
  804. int nCount = m_listType.GetItemCount();
  805. for (int i = 0; i < nCount; i++)
  806. {
  807. if (m_listType.GetItemData(i) == dwIndex)
  808. return i;
  809. }
  810. return nResult;
  811. }
  812. BOOL
  813. CFilterPage::IsDefaultType(DWORD dwType)
  814. {
  815. BOOL bDefault = FALSE;
  816. for (int i = 0; i < DimensionOf(s_NameTypeMappingDefault); i++)
  817. {
  818. if (s_NameTypeMappingDefault[i][0] == dwType)
  819. {
  820. bDefault = TRUE;
  821. break;
  822. }
  823. }
  824. return bDefault;
  825. }
  826. BOOL CFilterPage::OnHelpInfo(HELPINFO* pHelpInfo)
  827. {
  828. int i;
  829. DWORD dwCtrlId;
  830. if (pHelpInfo->iContextType == HELPINFO_WINDOW)
  831. {
  832. DWORD * pdwHelp = GetHelpMap();
  833. if (pdwHelp)
  834. {
  835. ::WinHelp ((HWND)pHelpInfo->hItemHandle,
  836. AfxGetApp()->m_pszHelpFilePath,
  837. HELP_WM_HELP,
  838. (ULONG_PTR)pdwHelp);
  839. }
  840. }
  841. return TRUE;
  842. }
  843. /////////////////////////////////////////////////////////////////////////////
  844. // CNameTypeDlg dialog
  845. CNameTypeDlg::CNameTypeDlg(CWnd* pParent /*=NULL*/)
  846. : CBaseDialog(CNameTypeDlg::IDD, pParent)
  847. {
  848. //{{AFX_DATA_INIT(CNameTypeDlg)
  849. m_strDescription = _T("");
  850. m_strId = _T("");
  851. //}}AFX_DATA_INIT
  852. m_fCreate = TRUE;
  853. m_dwId = 0;
  854. }
  855. void CNameTypeDlg::DoDataExchange(CDataExchange* pDX)
  856. {
  857. CBaseDialog::DoDataExchange(pDX);
  858. //{{AFX_DATA_MAP(CNameTypeDlg)
  859. DDX_Control(pDX, IDC_EDIT_NAME_TYPE_DESCRIPTION, m_editDescription);
  860. DDX_Control(pDX, IDC_EDIT_NAME_TYPE_ID, m_editId);
  861. DDX_Text(pDX, IDC_EDIT_NAME_TYPE_DESCRIPTION, m_strDescription);
  862. DDX_Text(pDX, IDC_EDIT_NAME_TYPE_ID, m_strId);
  863. //}}AFX_DATA_MAP
  864. }
  865. BEGIN_MESSAGE_MAP(CNameTypeDlg, CBaseDialog)
  866. //{{AFX_MSG_MAP(CNameTypeDlg)
  867. //}}AFX_MSG_MAP
  868. END_MESSAGE_MAP()
  869. /////////////////////////////////////////////////////////////////////////////
  870. // CNameTypeDlg message handlers
  871. BOOL CNameTypeDlg::OnInitDialog()
  872. {
  873. CBaseDialog::OnInitDialog();
  874. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  875. if (!m_fCreate)
  876. {
  877. CString strTitle;
  878. strTitle.LoadString(IDS_MODIFY_NAME_TYPE);
  879. SetWindowText(strTitle);
  880. m_editId.SetReadOnly(TRUE);
  881. CString strId;
  882. strId.Format(_T("%lx"), m_dwId);
  883. m_editId.SetWindowText(strId);
  884. }
  885. m_editId.LimitText(2);
  886. m_editDescription.LimitText(STRING_LENGTH_MAX);
  887. return TRUE; // return TRUE unless you set the focus to a control
  888. // EXCEPTION: OCX Property Pages should return FALSE
  889. }
  890. void CNameTypeDlg::OnOK()
  891. {
  892. UpdateData();
  893. TCHAR * pEnd;
  894. // convert the id
  895. m_dwId = _tcstol(m_strId, &pEnd, 16);
  896. if (*pEnd != NULL)
  897. {
  898. AfxMessageBox(IDS_ERR_INVALID_HEX_STRING);
  899. m_editId.SetSel(0, -1);
  900. m_editId.SetFocus();
  901. return;
  902. }
  903. if (m_fCreate && m_pNameTypeMap->EntryExists(m_dwId))
  904. {
  905. AfxMessageBox(IDS_ERROR_NAME_TYPE_EXISTS);
  906. m_editId.SetFocus();
  907. return;
  908. }
  909. CBaseDialog::OnOK();
  910. }
  911. /////////////////////////////////////////////////////////////////////////////
  912. // CIPAddrPage property page
  913. IMPLEMENT_DYNCREATE(CIPAddrPage, CPropertyPage)
  914. CIPAddrPage::CIPAddrPage() : CPropertyPage(CIPAddrPage::IDD)
  915. {
  916. //{{AFX_DATA_INIT(CIPAddrPage)
  917. //}}AFX_DATA_INIT
  918. }
  919. CIPAddrPage::~CIPAddrPage()
  920. {
  921. }
  922. LPCOLESTR CIPAddrPage::GetNameForApi()
  923. {
  924. return m_bFilterName == TRUE ? (LPCOLESTR)m_strName : NULL;
  925. }
  926. DWORD CIPAddrPage::GetIPMaskForFilter(UINT nMask)
  927. {
  928. return m_bFilterIpMask == TRUE ? m_dwaIPMasks[nMask] : INADDR_BROADCAST;
  929. }
  930. void CIPAddrPage::DoDataExchange(CDataExchange* pDX)
  931. {
  932. CPropertyPage::DoDataExchange(pDX);
  933. //{{AFX_DATA_MAP(CIPAddrPage)
  934. DDX_Control(pDX, IDC_CHECK_MATCHCASE, m_ckbMatchCase);
  935. DDX_Control(pDX, IDC_CHECK_IPMASK, m_ckbIPMask);
  936. DDX_Control(pDX, IDC_CHECK_NAME, m_ckbName);
  937. DDX_Control(pDX, IDC_CHECK_IPADDR, m_ckbIPAddr);
  938. DDX_Control(pDX, IDC_ENABLE_CACHING, m_btnEnableCache);
  939. DDX_Control(pDX, IDC_EDIT_NAME, m_editName);
  940. DDX_Control(pDX, IDC_IPADDRESS, m_ctrlIPAddress);
  941. DDX_Control(pDX, IDC_SUBNETMASK, m_ctrlIPMask);
  942. //}}AFX_DATA_MAP
  943. }
  944. BEGIN_MESSAGE_MAP(CIPAddrPage, CPropertyPage)
  945. //{{AFX_MSG_MAP(CIPAddrPage)
  946. ON_BN_CLICKED(IDC_CHECK_IPADDR, OnCheckIpaddr)
  947. ON_BN_CLICKED(IDC_CHECK_NAME, OnCheckName)
  948. ON_BN_CLICKED(IDC_ENABLE_CACHING, OnEnableCaching)
  949. ON_BN_CLICKED(IDC_CHECK_IPMASK, OnCheckIpmask)
  950. ON_WM_HELPINFO()
  951. //}}AFX_MSG_MAP
  952. END_MESSAGE_MAP()
  953. /////////////////////////////////////////////////////////////////////////////
  954. // CIPAddrPage message handlers
  955. void CIPAddrPage::OnOK()
  956. {
  957. DWORD dwAddress, dwMask;
  958. CString oldName;
  959. CLoadRecords *pSheet = (CLoadRecords *)GetParent();
  960. pSheet->m_nActivePage = pSheet->GetActiveIndex();
  961. pSheet->m_bEnableCache = pSheet->m_bCaching;
  962. //------------check the name field--------------
  963. m_bFilterName = (m_ckbName.GetCheck() == 1);
  964. m_bMatchCase = (m_ckbMatchCase.GetCheck() == 1);
  965. // get a hand on the original name
  966. oldName = m_strName;
  967. // get the current name
  968. m_editName.GetWindowText(m_strName);
  969. if (!m_bDirtyName && !m_bFilterName)
  970. // if we didn't filter by name before and we don't now, the name is clean
  971. m_bDirtyName = FALSE;
  972. else if (m_bDirtyName && !m_bFilterName)
  973. // if we did filter before and we don't now, the name is dirty
  974. m_bDirtyName = TRUE;
  975. else if (!m_bDirtyName && m_bFilterName)
  976. // if we didn't filter before and we do now, the name is clean
  977. m_bDirtyName = FALSE;
  978. else
  979. {
  980. // we did filter by name before, we do now
  981. // the filter might have changed
  982. LPCTSTR pOldName, pNewName;
  983. // we should mark the name "dirty" only if the old prefix is included in the new one
  984. // meaning all new names should already be loaded in the database view since
  985. // they match the old prefix
  986. for (pOldName = (LPCTSTR)oldName, pNewName = (LPCTSTR)m_strName;
  987. *pNewName != _T('\0') && *pNewName != _T('*') && *pNewName != _T('?');
  988. pOldName++, pNewName++)
  989. {
  990. if (*pOldName != *pNewName)
  991. break;
  992. }
  993. m_bDirtyName = (*pOldName != _T('\0') &&
  994. *pOldName != _T('*') &&
  995. *pOldName != _T('?'));
  996. }
  997. //------------check the IP address and mask fields--------------
  998. m_bFilterIpAddr = (m_ckbIPAddr.GetCheck() == 1);
  999. m_bFilterIpMask = (m_ckbIPMask.GetCheck() == 1);
  1000. // get the current address and mask
  1001. m_ctrlIPAddress.GetAddress(dwAddress);
  1002. m_ctrlIPMask.GetAddress(dwMask);
  1003. if (m_bDirtyAddr && m_bDirtyMask)
  1004. {
  1005. // we did have a mask before
  1006. if (m_bFilterIpAddr && m_bFilterIpMask)
  1007. {
  1008. // we do have a mask now - if the new mask is less specific, => definitely dirty
  1009. m_bDirtyMask = ((dwMask|m_dwaIPMasks[0])^dwMask) != 0;
  1010. }
  1011. else
  1012. {
  1013. // we don't have a mask now => 255.255.255.255 (which is assumed) is as specific
  1014. // as possible => we do have the record we need already => definitely clean
  1015. m_bDirtyMask = FALSE;
  1016. }
  1017. }
  1018. else
  1019. {
  1020. // we didn't have a mask before => 255.255.255.255 was assumed = the most specific
  1021. if (m_bFilterIpAddr && m_bFilterIpMask)
  1022. {
  1023. // we do have a mask now
  1024. // the mask is dirty only if we actually did IP filtering before,
  1025. // otherwise, all the records are already there, regardless their IPs
  1026. m_bDirtyMask = m_bDirtyAddr && (dwMask != INADDR_BROADCAST);
  1027. }
  1028. else
  1029. {
  1030. // we don't have a mask now => nothing changed => definitely clean
  1031. m_bDirtyMask = FALSE;
  1032. }
  1033. }
  1034. if (m_bDirtyAddr)
  1035. {
  1036. // we did filter on IP address
  1037. if (m_bFilterIpAddr)
  1038. {
  1039. // we do filter on IP address now
  1040. // we need to see if the new Ip (or subnet address) has changed
  1041. //DWORD dwNewSubnet, dwOldSubnet;
  1042. //dwNewSubnet = m_bFilterIpMask ? dwAddress & dwMask : dwAddress;
  1043. //dwOldSubnet = m_bDirtyMask ? m_dwaIPAddrs[0] & m_dwaIPMasks[0] : m_dwaIPAddrs[0];
  1044. m_bDirtyAddr = (dwAddress != m_dwaIPAddrs[0]);
  1045. }
  1046. else
  1047. {
  1048. // we don't filter on IP address now => definitely dirty
  1049. m_bDirtyAddr = TRUE;
  1050. }
  1051. }
  1052. else
  1053. {
  1054. // we didn't filter on IP address originally => we have all records => definitely clean
  1055. m_bDirtyAddr = FALSE;
  1056. }
  1057. // save the current address but only if there is one! The ip ctrl could very well be empty and we
  1058. // risk to see this as 0.0.0.0 which would be wrong
  1059. m_dwaIPAddrs.RemoveAll();
  1060. if (!m_ctrlIPAddress.IsBlank())
  1061. m_dwaIPAddrs.Add(dwAddress);
  1062. // save the current mask but only if there is one! The ip ctrl could very well be empty and we
  1063. // risk to see this as 0.0.0.0 which would be wrong
  1064. m_dwaIPMasks.RemoveAll();
  1065. if (!m_ctrlIPMask.IsBlank())
  1066. m_dwaIPMasks.Add(dwMask);
  1067. CPropertyPage::OnOK();
  1068. }
  1069. BOOL CIPAddrPage::OnInitDialog()
  1070. {
  1071. CPropertyPage::OnInitDialog();
  1072. // turn on the ? in the title bar
  1073. CWnd * pWnd = GetParent();
  1074. if (pWnd)
  1075. {
  1076. CWnd * pButton = pWnd->GetDlgItem(IDOK);
  1077. if (pButton)
  1078. {
  1079. CString strText;
  1080. strText.LoadString(IDS_FIND_NOW);
  1081. pButton->SetWindowText(strText);
  1082. }
  1083. pWnd->ModifyStyleEx(0, WS_EX_CONTEXTHELP, 0);
  1084. }
  1085. SetModified();
  1086. // just save the previous "filter by name" bit
  1087. m_bDirtyName = m_bFilterName;
  1088. m_ckbName.SetCheck(m_bFilterName);
  1089. m_ckbMatchCase.SetCheck(m_bMatchCase);
  1090. m_ckbMatchCase.EnableWindow(m_bFilterName);
  1091. m_editName.SetWindowText(m_strName);
  1092. m_editName.EnableWindow(m_bFilterName);
  1093. // just save the previous "filter by ip" bit
  1094. m_bDirtyAddr = m_bFilterIpAddr;
  1095. m_ckbIPAddr.SetCheck(m_bFilterIpAddr);
  1096. if (m_dwaIPAddrs.GetSize() != 0)
  1097. m_ctrlIPAddress.SetAddress(m_dwaIPAddrs[0]);
  1098. m_ctrlIPAddress.EnableWindow(m_bFilterIpAddr);
  1099. m_ckbIPMask.EnableWindow(m_bFilterIpAddr);
  1100. // just save the previous "filter by subnet" bit
  1101. m_bDirtyMask = m_bFilterIpMask;
  1102. m_ckbIPMask.SetCheck(m_bFilterIpMask);
  1103. if (m_dwaIPMasks.GetSize() != 0)
  1104. m_ctrlIPMask.SetAddress(m_dwaIPMasks[0]);
  1105. m_ctrlIPMask.EnableWindow(m_bFilterIpAddr && m_bFilterIpMask);
  1106. return TRUE; // return TRUE unless you set the focus to a control
  1107. // EXCEPTION: OCX Property Pages should return FALSE
  1108. }
  1109. void CIPAddrPage::OnCheckIpaddr()
  1110. {
  1111. BOOL bFIpAddr = (m_ckbIPAddr.GetCheck() == 1);
  1112. BOOL bFIpMask = (m_ckbIPMask.GetCheck() == 1);
  1113. m_ctrlIPAddress.EnableWindow(bFIpAddr);
  1114. m_ckbIPMask.EnableWindow(bFIpAddr);
  1115. m_ctrlIPMask.EnableWindow(bFIpAddr && bFIpMask);
  1116. m_ctrlIPAddress.SetFieldFocus((WORD)-1);
  1117. }
  1118. void CIPAddrPage::OnCheckIpmask()
  1119. {
  1120. BOOL bFIpMask = (m_ckbIPMask.GetCheck() == 1);
  1121. m_ctrlIPMask.EnableWindow(bFIpMask);
  1122. m_ctrlIPMask.SetFieldFocus((WORD)-1);
  1123. }
  1124. void CIPAddrPage::OnCheckName()
  1125. {
  1126. TCHAR pName[3];
  1127. BOOL bFName = (m_ckbName.GetCheck() == 1);
  1128. CLoadRecords *pParent = (CLoadRecords *)GetParent();
  1129. m_editName.EnableWindow(bFName);
  1130. m_ckbMatchCase.EnableWindow(bFName);
  1131. }
  1132. BOOL CIPAddrPage::OnKillActive()
  1133. {
  1134. BOOL bFName = (m_ckbName.GetCheck() == 1);
  1135. BOOL bFIpAddr = (m_ckbIPAddr.GetCheck() == 1);
  1136. BOOL bFIpMask = (m_ckbIPMask.GetCheck() == 1);
  1137. if (bFName && m_editName.GetWindowTextLength()==0)
  1138. {
  1139. WinsMessageBox(IDS_ERR_NO_NAME);
  1140. return FALSE;
  1141. }
  1142. if (bFIpAddr && m_ctrlIPAddress.IsBlank())
  1143. {
  1144. WinsMessageBox(IDS_ERR_NO_IPADDR);
  1145. return FALSE;
  1146. }
  1147. if (bFIpAddr && bFIpMask)
  1148. {
  1149. if (m_ctrlIPMask.IsBlank())
  1150. {
  1151. WinsMessageBox(IDS_ERR_NO_IPMASK);
  1152. return FALSE;
  1153. }
  1154. else
  1155. {
  1156. DWORD dwMask;
  1157. m_ctrlIPMask.GetAddress(dwMask);
  1158. if (dwMask != ~(((dwMask-1)|dwMask)^dwMask))
  1159. {
  1160. WinsMessageBox(IDS_ERR_INVALID_IPMASK);
  1161. return FALSE;
  1162. }
  1163. }
  1164. }
  1165. return CPropertyPage::OnKillActive();
  1166. }
  1167. BOOL CIPAddrPage::OnSetActive()
  1168. {
  1169. CLoadRecords *pParent = (CLoadRecords *)GetParent();
  1170. m_btnEnableCache.SetCheck(pParent->m_bCaching);
  1171. return CPropertyPage::OnSetActive();
  1172. }
  1173. void CIPAddrPage::OnEnableCaching()
  1174. {
  1175. CLoadRecords *pParent = (CLoadRecords *)GetParent();
  1176. pParent->m_bCaching = (m_btnEnableCache.GetCheck() == 1);
  1177. }
  1178. BOOL CIPAddrPage::OnHelpInfo(HELPINFO* pHelpInfo)
  1179. {
  1180. int i;
  1181. DWORD dwCtrlId;
  1182. if (pHelpInfo->iContextType == HELPINFO_WINDOW)
  1183. {
  1184. DWORD * pdwHelp = GetHelpMap();
  1185. if (pdwHelp)
  1186. {
  1187. ::WinHelp ((HWND)pHelpInfo->hItemHandle,
  1188. AfxGetApp()->m_pszHelpFilePath,
  1189. HELP_WM_HELP,
  1190. (ULONG_PTR)pdwHelp);
  1191. }
  1192. }
  1193. return TRUE;
  1194. }