Source code of Windows XP (NT5)
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.

2362 lines
56 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: uiutil.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "preDNSsn.h"
  11. #include <SnapBase.h>
  12. #include "resource.h"
  13. #include "dnsutil.h"
  14. #include "DNSSnap.h"
  15. #include "snapdata.h"
  16. #include "server.h"
  17. #include "domain.h"
  18. #include "zone.h"
  19. #include "serverui.h"
  20. #include "uiutil.h"
  21. #ifdef DEBUG_ALLOCATOR
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27. #endif
  28. ////////////////////////////////////////////////////////////////////////////
  29. // CDNSNameTokenizer
  30. CDNSNameTokenizer::CDNSNameTokenizer(PCWSTR pszDNSName)
  31. {
  32. ASSERT(pszDNSName != NULL);
  33. m_szDNSName = pszDNSName;
  34. }
  35. CDNSNameTokenizer::~CDNSNameTokenizer()
  36. {
  37. }
  38. BOOL CDNSNameTokenizer::Tokenize(const wchar_t* wcToken)
  39. {
  40. BOOL bRet = TRUE;
  41. PWSTR pszToken = new WCHAR[m_szDNSName.GetLength() + 1];
  42. if (pszToken != NULL)
  43. {
  44. wcscpy(pszToken, m_szDNSName);
  45. PWSTR pszNextToken = wcstok(pszToken, wcToken);
  46. while (pszNextToken != NULL)
  47. {
  48. AddTail(pszNextToken);
  49. pszNextToken = wcstok(NULL, wcToken);
  50. }
  51. delete[] pszToken;
  52. pszToken = NULL;
  53. }
  54. else
  55. {
  56. bRet = FALSE;
  57. }
  58. return bRet;
  59. }
  60. void CDNSNameTokenizer::RemoveMatchingFromTail(CDNSNameTokenizer& refTokenizer)
  61. {
  62. //
  63. // Removes matching tokens from the tail until one of the tokenizers is empty
  64. // or we come across mismatched tokens
  65. //
  66. while (GetCount() > 0 && refTokenizer.GetCount() > 0)
  67. {
  68. if (GetTail() == refTokenizer.GetTail())
  69. {
  70. RemoveTail();
  71. refTokenizer.RemoveTail();
  72. }
  73. else
  74. {
  75. break;
  76. }
  77. }
  78. }
  79. void CDNSNameTokenizer::GetRemaining(CString& strrefRemaining, const wchar_t* wcToken)
  80. {
  81. //
  82. // Copies the remaining tokens into a string delimited by the token passed in
  83. //
  84. strrefRemaining.Empty();
  85. POSITION pos = GetHeadPosition();
  86. while (pos != NULL)
  87. {
  88. strrefRemaining += GetNext(pos);
  89. if (pos != NULL)
  90. {
  91. strrefRemaining += wcToken;
  92. }
  93. }
  94. }
  95. ////////////////////////////////////////////////////////////////////////////
  96. // Global functions
  97. BOOL LoadStringsToComboBox(HINSTANCE hInstance, CComboBox* pCombo,
  98. UINT nStringID, UINT nMaxLen, UINT nMaxAddCount)
  99. {
  100. pCombo->ResetContent();
  101. ASSERT(hInstance != NULL);
  102. WCHAR* szBuf = (WCHAR*)malloc(sizeof(WCHAR)*nMaxLen);
  103. if (!szBuf)
  104. {
  105. return FALSE;
  106. }
  107. BOOL bRet = TRUE;
  108. LPWSTR* lpszArr = 0;
  109. do // false loop
  110. {
  111. if ( ::LoadString(hInstance, nStringID, szBuf, nMaxLen) == 0)
  112. {
  113. bRet = FALSE;
  114. break;
  115. }
  116. lpszArr = (LPWSTR*)malloc(sizeof(LPWSTR*)*nMaxLen);
  117. if (!lpszArr)
  118. {
  119. bRet = FALSE;
  120. break;
  121. }
  122. UINT nArrEntries;
  123. ParseNewLineSeparatedString(szBuf,lpszArr, &nArrEntries);
  124. if (nMaxAddCount < nArrEntries) nArrEntries = nMaxAddCount;
  125. for (UINT k=0; k<nArrEntries; k++)
  126. pCombo->AddString(lpszArr[k]);
  127. } while (false);
  128. if (szBuf)
  129. {
  130. free(szBuf);
  131. szBuf = 0;
  132. }
  133. if (lpszArr)
  134. {
  135. free(lpszArr);
  136. lpszArr = 0;
  137. }
  138. return bRet;
  139. }
  140. void ParseNewLineSeparatedString(LPWSTR lpsz,
  141. LPWSTR* lpszArr,
  142. UINT* pnArrEntries)
  143. {
  144. static WCHAR lpszSep[] = L"\n";
  145. *pnArrEntries = 0;
  146. int k = 0;
  147. lpszArr[k] = wcstok(lpsz, lpszSep);
  148. if (lpszArr[k] == NULL)
  149. return;
  150. while (TRUE)
  151. {
  152. WCHAR* lpszToken = wcstok(NULL, lpszSep);
  153. if (lpszToken != NULL)
  154. lpszArr[++k] = lpszToken;
  155. else
  156. break;
  157. }
  158. *pnArrEntries = k+1;
  159. }
  160. void LoadStringArrayFromResource(LPWSTR* lpszArr,
  161. UINT* nStringIDs,
  162. int nArrEntries,
  163. int* pnSuccessEntries)
  164. {
  165. CString szTemp;
  166. *pnSuccessEntries = 0;
  167. for (int k = 0;k < nArrEntries; k++)
  168. {
  169. if (!szTemp.LoadString(nStringIDs[k]))
  170. {
  171. lpszArr[k] = NULL;
  172. continue;
  173. }
  174. int iLength = szTemp.GetLength() + 1;
  175. lpszArr[k] = (LPWSTR)malloc(sizeof(WCHAR)*iLength);
  176. if (lpszArr[k] != NULL)
  177. {
  178. wcscpy(lpszArr[k], (LPWSTR)(LPCWSTR)szTemp);
  179. (*pnSuccessEntries)++;
  180. }
  181. }
  182. }
  183. void EnumerateMTNodeHelper(CMTContainerNode* pNode,
  184. CComponentDataObject* pComponentData)
  185. {
  186. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  187. //TRACE(_T("before CLongOperationDialog::DoModal()\n"));
  188. HWND hWnd = NULL;
  189. HRESULT hr = pComponentData->GetConsole()->GetMainWindow(&hWnd);
  190. ASSERT(SUCCEEDED(hr));
  191. CWnd* pParentWnd = CWnd::FromHandle(hWnd);
  192. CLongOperationDialog dlg(
  193. new CNodeEnumerationThread(pComponentData,pNode),
  194. pParentWnd,
  195. IDR_SEARCH_AVI);
  196. dlg.DoModal();
  197. //TRACE(_T("after CLongOperationDialog::DoModal()\n"));
  198. }
  199. void _EnableEditableControlHelper(HWND hWnd, BOOL bEnable)
  200. {
  201. WCHAR szBuf[256];
  202. ::GetClassName(hWnd, szBuf, 256);
  203. if (wcscmp(szBuf, TEXT("Static")) != 0)
  204. ::EnableWindow(hWnd, bEnable);
  205. }
  206. void EnableDialogControls(HWND hWnd, BOOL bEnable)
  207. {
  208. HWND hWndCurr = ::GetWindow(hWnd, GW_CHILD);
  209. if (hWndCurr != NULL)
  210. {
  211. _EnableEditableControlHelper(hWndCurr, bEnable);
  212. hWndCurr = ::GetNextWindow(hWndCurr, GW_HWNDNEXT);
  213. while (hWndCurr)
  214. {
  215. _EnableEditableControlHelper(hWndCurr, bEnable);
  216. hWndCurr = ::GetNextWindow(hWndCurr, GW_HWNDNEXT);
  217. }
  218. }
  219. }
  220. BOOL LoadFontInfoFromResource(IN UINT nFontNameID,
  221. IN UINT nFontSizeID,
  222. OUT LPWSTR lpFontName, IN int nFontNameMaxchar,
  223. OUT int& nFontSize,
  224. IN LPCWSTR lpszDefaultFont, IN int nDefaultFontSize)
  225. {
  226. BOOL bRes = FALSE;
  227. if (0 == ::LoadString(_Module.GetResourceInstance(), nFontNameID,
  228. lpFontName, nFontNameMaxchar))
  229. {
  230. wcscpy(lpFontName, lpszDefaultFont);
  231. }
  232. else
  233. {
  234. bRes = TRUE;
  235. }
  236. WCHAR szFontSize[128];
  237. if (0 != ::LoadString(_Module.GetResourceInstance(), nFontSizeID,
  238. szFontSize, sizeof(szFontSize)/sizeof(WCHAR)))
  239. {
  240. nFontSize = _wtoi(szFontSize);
  241. if (nFontSize == 0)
  242. nFontSize = nDefaultFontSize;
  243. else
  244. bRes = TRUE;
  245. }
  246. else
  247. {
  248. nFontSize = nDefaultFontSize;
  249. }
  250. return bRes;
  251. }
  252. void InitBigBoldFont(HWND hWnd, HFONT& hFont)
  253. {
  254. ASSERT(::IsWindow(hWnd));
  255. NONCLIENTMETRICS ncm;
  256. memset(&ncm, 0, sizeof(ncm));
  257. ncm.cbSize = sizeof(ncm);
  258. ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);
  259. LOGFONT boldLogFont = ncm.lfMessageFont;
  260. boldLogFont.lfWeight = FW_BOLD;
  261. int nFontSize = 0;
  262. VERIFY(LoadFontInfoFromResource(IDS_BIG_BOLD_FONT_NAME,
  263. IDS_BIG_BOLD_FONT_SIZE,
  264. boldLogFont.lfFaceName, LF_FACESIZE,
  265. nFontSize,
  266. L"Verdana Bold", 12 // default if something goes wrong
  267. ));
  268. HDC hdc = ::GetDC(hWnd);
  269. if (hdc != NULL)
  270. {
  271. boldLogFont.lfHeight = 0 - (::GetDeviceCaps(hdc, LOGPIXELSY) * nFontSize / 72);
  272. hFont = ::CreateFontIndirect((const LOGFONT*)(&boldLogFont));
  273. ::ReleaseDC(hWnd, hdc);
  274. }
  275. }
  276. void SetBigBoldFont(HWND hWndDialog, int nControlID)
  277. {
  278. ASSERT(::IsWindow(hWndDialog));
  279. ASSERT(nControlID);
  280. static HFONT boldLogFont = 0;
  281. if (boldLogFont == 0)
  282. {
  283. InitBigBoldFont(hWndDialog, boldLogFont);
  284. }
  285. HWND hWndControl = ::GetDlgItem(hWndDialog, nControlID);
  286. if (hWndControl)
  287. {
  288. ::SendMessage(hWndControl, WM_SETFONT, (WPARAM)boldLogFont, MAKELPARAM(TRUE, 0));
  289. }
  290. }
  291. int GetCheckedRadioButtonHelper(HWND hDlg, int nCount, int* nRadioArr, int nRadioDefault)
  292. {
  293. ASSERT(::IsWindow(hDlg));
  294. ASSERT(nCount > 0);
  295. for (int k=0; k<nCount; k++)
  296. {
  297. HWND hRadio = ::GetDlgItem(hDlg, nRadioArr[k]);
  298. ASSERT(hRadio != NULL);
  299. if ((hRadio != NULL) && (BST_CHECKED == ::SendMessage(hRadio, BM_GETCHECK, 0, 0)))
  300. return nRadioArr[k];
  301. }
  302. ASSERT(FALSE);
  303. return nRadioDefault;
  304. }
  305. ////////////////////////////////////////////////////////////////////////////
  306. // CMultiselectErrorDialog
  307. BEGIN_MESSAGE_MAP(CMultiselectErrorDialog, CDialog)
  308. END_MESSAGE_MAP()
  309. HRESULT CMultiselectErrorDialog::Initialize(CNodeList* pNodeList,
  310. DNS_STATUS* pErrorArray,
  311. UINT nErrorCount,
  312. PCWSTR pszTitle,
  313. PCWSTR pszCaption,
  314. PCWSTR pszColumnHeader)
  315. {
  316. ASSERT(pNodeList != NULL);
  317. ASSERT(pErrorArray != NULL);
  318. ASSERT(pszTitle != NULL);
  319. ASSERT(pszCaption != NULL);
  320. ASSERT(pszColumnHeader != NULL);
  321. if (pNodeList == NULL ||
  322. pErrorArray == NULL ||
  323. pszTitle == NULL ||
  324. pszCaption == NULL ||
  325. pszColumnHeader == NULL)
  326. {
  327. return E_POINTER;
  328. }
  329. m_pNodeList = pNodeList;
  330. m_pErrorArray = pErrorArray;
  331. m_nErrorCount = nErrorCount;
  332. m_szTitle = pszTitle;
  333. m_szCaption = pszCaption;
  334. m_szColumnHeader = pszColumnHeader;
  335. return S_OK;
  336. }
  337. const int OBJ_LIST_NAME_COL_WIDTH = 100;
  338. const int IDX_NAME_COL = 0;
  339. const int IDX_ERR_COL = 1;
  340. BOOL CMultiselectErrorDialog::OnInitDialog()
  341. {
  342. CDialog::OnInitDialog();
  343. SetWindowText(m_szTitle);
  344. SetDlgItemText(IDC_STATIC_MESSAGE, m_szCaption);
  345. HWND hList = GetDlgItem(IDC_ERROR_LIST)->GetSafeHwnd();
  346. ListView_SetExtendedListViewStyle(hList, LVS_EX_FULLROWSELECT);
  347. //
  348. // Set the column headings.
  349. //
  350. RECT rect;
  351. ::GetClientRect(hList, &rect);
  352. LV_COLUMN lvc = {0};
  353. lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  354. lvc.fmt = LVCFMT_LEFT;
  355. lvc.cx = OBJ_LIST_NAME_COL_WIDTH;
  356. lvc.pszText = (PWSTR)(PCWSTR)m_szColumnHeader;
  357. lvc.iSubItem = IDX_NAME_COL;
  358. ListView_InsertColumn(hList, IDX_NAME_COL, &lvc);
  359. CString szError;
  360. VERIFY(szError.LoadString(IDS_ERROR));
  361. lvc.cx = rect.right - OBJ_LIST_NAME_COL_WIDTH;
  362. lvc.pszText = (PWSTR)(PCWSTR)szError;
  363. lvc.iSubItem = IDX_ERR_COL;
  364. ListView_InsertColumn(hList, IDX_ERR_COL, &lvc);
  365. //
  366. // Insert the errors
  367. //
  368. ASSERT(m_pErrorArray != NULL && m_pNodeList != NULL);
  369. UINT nIdx = 0;
  370. POSITION pos = m_pNodeList->GetHeadPosition();
  371. while (pos != NULL)
  372. {
  373. CTreeNode* pNode = m_pNodeList->GetNext(pos);
  374. if (pNode != NULL)
  375. {
  376. if (nIdx < m_nErrorCount && m_pErrorArray[nIdx] != 0)
  377. {
  378. //
  379. // Create the list view item
  380. //
  381. LV_ITEM lvi = {0};
  382. lvi.mask = LVIF_TEXT | LVIF_PARAM;
  383. lvi.iSubItem = IDX_NAME_COL;
  384. lvi.lParam = (LPARAM)pNode->GetDisplayName();
  385. lvi.pszText = (PWSTR)pNode->GetDisplayName();
  386. lvi.iItem = nIdx;
  387. //
  388. // Insert the new item
  389. //
  390. int NewIndex = ListView_InsertItem(hList, &lvi);
  391. ASSERT(NewIndex != -1);
  392. if (NewIndex == -1)
  393. {
  394. continue;
  395. }
  396. //
  397. // Get the error message
  398. //
  399. CString szErrorMessage;
  400. if (CDNSErrorInfo::GetErrorString(m_pErrorArray[nIdx],szErrorMessage))
  401. {
  402. ListView_SetItemText(hList, NewIndex, IDX_ERR_COL, (PWSTR)(PCWSTR)szErrorMessage);
  403. }
  404. }
  405. }
  406. }
  407. return TRUE;
  408. }
  409. ////////////////////////////////////////////////////////////////////////////
  410. // CDNSMaskCtrl
  411. // static alert function
  412. int CDNSMaskCtrl::AlertFunc(HWND, DWORD dwCurrent, DWORD dwLow, DWORD dwHigh)
  413. {
  414. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  415. CString szFormat;
  416. szFormat.LoadString(IDS_MASK_ALERT);
  417. CString s;
  418. s.Format((LPCWSTR)szFormat, dwCurrent, dwLow, dwHigh);
  419. AfxMessageBox(s);
  420. return 0;
  421. }
  422. BOOL CDNSMaskCtrl::IsBlank()
  423. {
  424. return static_cast<BOOL>(SendMessage(DNS_MASK_CTRL_ISBLANK, 0, 0));
  425. }
  426. void CDNSMaskCtrl::SetFocusField(DWORD dwField)
  427. {
  428. SendMessage(DNS_MASK_CTRL_SETFOCUS, dwField, 0);
  429. }
  430. void CDNSMaskCtrl::SetFieldRange(DWORD dwField, DWORD dwMin, DWORD dwMax)
  431. {
  432. SendMessage(DNS_MASK_CTRL_SET_LOW_RANGE, dwField, dwMin);
  433. SendMessage(DNS_MASK_CTRL_SET_HI_RANGE, dwField, dwMax);
  434. }
  435. void CDNSMaskCtrl::SetArray(DWORD* pArray, UINT nFields)
  436. {
  437. SendMessage(DNS_MASK_CTRL_SET, (WPARAM)pArray, (LPARAM)nFields);
  438. }
  439. void CDNSMaskCtrl::GetArray(DWORD* pArray, UINT nFields)
  440. {
  441. SendMessage(DNS_MASK_CTRL_GET, (WPARAM)pArray, (LPARAM)nFields);
  442. }
  443. void CDNSMaskCtrl::Clear(int nField)
  444. {
  445. SendMessage(DNS_MASK_CTRL_CLEAR, (WPARAM)nField, 0);
  446. }
  447. void CDNSMaskCtrl::SetAlertFunction( int (*lpfnAlert)(HWND, DWORD, DWORD, DWORD) )
  448. {
  449. SendMessage(DNS_MASK_CTRL_SET_ALERT, (WPARAM)lpfnAlert, 0);
  450. }
  451. void CDNSMaskCtrl::EnableField(int nField, BOOL bEnable)
  452. {
  453. SendMessage(DNS_MASK_CTRL_ENABLE_FIELD, (WPARAM)nField, (LPARAM)bEnable);
  454. }
  455. ////////////////////////////////////////////////////////////////////////////
  456. // CDNSIPv4Control
  457. void CDNSIPv4Control::SetIPv4Val(DWORD x)
  458. {
  459. DWORD dwArr[4];
  460. dwArr[3] = FIRST_IPADDRESS(x);
  461. dwArr[2] = SECOND_IPADDRESS(x);
  462. dwArr[1] = THIRD_IPADDRESS(x);
  463. dwArr[0] = FOURTH_IPADDRESS(x);
  464. SetArray(dwArr,4);
  465. }
  466. #define IP_FIELD_VALUE(x) ((x == FIELD_EMPTY) ? 0 : x)
  467. void CDNSIPv4Control::GetIPv4Val(DWORD* pX)
  468. {
  469. DWORD dwArr[4];
  470. GetArray(dwArr,4);
  471. // got an array of DWORDS, if a field has value FIELD_EMPTY,
  472. // need to assign a value of 0
  473. *pX = static_cast<DWORD>(MAKEIPADDRESS(IP_FIELD_VALUE(dwArr[3]),
  474. IP_FIELD_VALUE(dwArr[2]),
  475. IP_FIELD_VALUE(dwArr[1]),
  476. IP_FIELD_VALUE(dwArr[0])));
  477. }
  478. BOOL CDNSIPv4Control::IsEmpty()
  479. {
  480. DWORD dwArr[4];
  481. GetArray(dwArr,4);
  482. return ((dwArr[0] == FIELD_EMPTY) && (dwArr[1] == FIELD_EMPTY) &&
  483. (dwArr[2] == FIELD_EMPTY) && (dwArr[3] == FIELD_EMPTY));
  484. }
  485. ////////////////////////////////////////////////////////////////////////////
  486. // CDNSIPv6Control
  487. // REVIEW_MARCOC: need to do the same as the IPv4, with FIELD_EMPTY ==> zero
  488. void CDNSIPv6Control::SetIPv6Val(IPV6_ADDRESS* pIpv6Address)
  489. {
  490. // assume the format is a WORD[8] array
  491. DWORD dwArr[8]; // internal format, unpack
  492. for(int k=0; k<8; k++)
  493. {
  494. dwArr[k] = 0x0000FFFF & REVERSE_WORD_BYTES(pIpv6Address->IP6Word[k]);
  495. }
  496. SetArray(dwArr,8);
  497. }
  498. void CDNSIPv6Control::GetIPv6Val(IPV6_ADDRESS* pIpv6Address)
  499. {
  500. // assume the format is a WORD[8] array
  501. DWORD dwArr[8]; // internal format
  502. GetArray(dwArr,8);
  503. // got an array of DWORDS, to move into WORD[8]
  504. // if a field has value FIELD_EMPTY, need to assign a value of 0
  505. for(int k=0; k<8; k++)
  506. {
  507. if (dwArr[k] == FIELD_EMPTY)
  508. pIpv6Address->IP6Word[k] = (WORD)0;
  509. else
  510. {
  511. ASSERT(HIWORD(dwArr[k]) == 0x0);
  512. pIpv6Address->IP6Word[k] = REVERSE_WORD_BYTES(LOWORD(dwArr[k]));
  513. }
  514. }
  515. }
  516. ////////////////////////////////////////////////////////////////////////////
  517. // CDNSTTLControl
  518. void CDNSTTLControl::SetTTL(DWORD x)
  519. {
  520. DWORD dwArr[4];
  521. // have to change from seconds into DDD:HH:MM:SS
  522. DWORD dwMin = x/60;
  523. dwArr[3] = x - dwMin*60; // # of seconds left
  524. DWORD dwHours = dwMin/60;
  525. dwArr[2] = dwMin - dwHours*60; // # of minutes left
  526. DWORD dwDays = dwHours/24;
  527. dwArr[1] = dwHours - dwDays*24; // # of hours left
  528. dwArr[0] = dwDays; // # of days left
  529. SetArray(dwArr,4);
  530. }
  531. void CDNSTTLControl::GetTTL(DWORD* pX)
  532. {
  533. // REVIEW_MARCOC: how do we deal with an empty field?
  534. // do we force zero on it? Should we do it in the UI when exiting a field?
  535. DWORD dwArr[4];
  536. GetArray(dwArr,4);
  537. // treat empty field as zero
  538. for(int j=0; j<4;j++)
  539. if (dwArr[j] == FIELD_EMPTY)
  540. dwArr[j] = 0;
  541. // have to convert back into seconds from DDD:HH:MM:SS
  542. *pX = dwArr[0]*3600*24 // days
  543. + dwArr[1]*3600 // hours
  544. + dwArr[2]*60 // minutes
  545. + dwArr[3]; // seconds
  546. // the max value is FFFFFFFF, that is 49710 days, 6 hours, 28 minutes and 15 seconds
  547. // field validation allows to get to 49710 days, 23 hours, 59 minutes and 59 seconds
  548. // causing wraparound
  549. if (*pX < dwArr[0]*3600*24) // wrapped around
  550. *pX = 0xFFFFFFFF; // max value
  551. }
  552. ///////////////////////////////////////////////////////////////////////
  553. // CDNSUnsignedIntEdit
  554. BEGIN_MESSAGE_MAP(CDNSUnsignedIntEdit, CEdit)
  555. ON_CONTROL_REFLECT(EN_KILLFOCUS, OnKillFocus)
  556. END_MESSAGE_MAP()
  557. UINT _StrToUint(LPCTSTR sz)
  558. {
  559. LONG n = 0;
  560. while (*sz != NULL)
  561. {
  562. LONG nPrev = n;
  563. n = n*10 + (TCHAR)(*sz - TEXT('0') ); // assume it is a digit
  564. if (nPrev > n || n > UINT_MAX)
  565. return (UINT)-1; // wrapped
  566. sz++;
  567. }
  568. return (UINT)n;
  569. }
  570. UINT _ForceToRange(UINT nVal, UINT nMin, UINT nMax)
  571. {
  572. if (nVal < nMin)
  573. nVal = nMin;
  574. else if( nVal > nMax)
  575. nVal = nMax;
  576. return nVal;
  577. }
  578. BOOL CDNSUnsignedIntEdit::SetVal(UINT nVal)
  579. {
  580. UINT n = _ForceToRange(nVal, m_nMin, m_nMax);
  581. TCHAR szBuf[128];
  582. wsprintf(szBuf, _T("%u"), n);
  583. SetWindowText(szBuf);
  584. return (nVal == n);
  585. }
  586. UINT CDNSUnsignedIntEdit::GetVal()
  587. {
  588. TCHAR szBuf[128] = {0};
  589. GetWindowText(szBuf,128);
  590. return _StrToUint(szBuf);
  591. }
  592. void CDNSUnsignedIntEdit::OnKillFocus()
  593. {
  594. UINT nVal = GetVal();
  595. UINT n = _ForceToRange(nVal, m_nMin, m_nMax);
  596. if ( (n != nVal) || (nVal == (UINT)-1) )
  597. SetVal(n);
  598. }
  599. ///////////////////////////////////////////////////////////////////////
  600. // CDNSUpDownUnsignedIntEdit
  601. BEGIN_MESSAGE_MAP(CDNSUpDownUnsignedIntEdit, CDNSUnsignedIntEdit)
  602. ON_CONTROL_REFLECT(EN_KILLFOCUS, OnKillFocus)
  603. ON_CONTROL_REFLECT(EN_CHANGE, OnChange)
  604. END_MESSAGE_MAP()
  605. void CDNSUpDownUnsignedIntEdit::OnKillFocus()
  606. {
  607. CDNSUnsignedIntEdit::OnKillFocus();
  608. m_pEditGroup->SetButtonsState();
  609. }
  610. void CDNSUpDownUnsignedIntEdit::OnChange()
  611. {
  612. m_pEditGroup->OnEditChange();
  613. }
  614. ///////////////////////////////////////////////////////////////////////
  615. // CDNSUpDownButton
  616. BEGIN_MESSAGE_MAP(CDNSUpDownButton, CButton)
  617. ON_CONTROL_REFLECT(BN_CLICKED, OnClicked)
  618. END_MESSAGE_MAP()
  619. void CDNSUpDownButton::OnClicked()
  620. {
  621. m_pEditGroup->OnClicked(m_bUp);
  622. }
  623. ///////////////////////////////////////////////////////////////////////
  624. // CDNSUpDownUnsignedIntEditGroup
  625. void CDNSUpDownUnsignedIntEditGroup::SetVal(UINT nVal)
  626. {
  627. m_edit.SetVal(nVal);
  628. SetButtonsState();
  629. }
  630. UINT CDNSUpDownUnsignedIntEditGroup::GetVal()
  631. {
  632. return m_edit.GetVal();
  633. }
  634. void CDNSUpDownUnsignedIntEditGroup::OnClicked(BOOL bUp)
  635. {
  636. UINT n = m_edit.GetVal();
  637. if (bUp)
  638. {
  639. m_edit.SetVal(++n);
  640. }
  641. else
  642. {
  643. m_edit.SetVal(--n);
  644. }
  645. SetButtonsState();
  646. }
  647. BOOL CDNSUpDownUnsignedIntEditGroup::Initialize(CWnd* pParentWnd, UINT nIDEdit,
  648. UINT nIDBtnUp, UINT nIDBtnDown)
  649. {
  650. ASSERT(pParentWnd != NULL);
  651. if (pParentWnd == NULL)
  652. return FALSE;
  653. m_edit.Set(this);
  654. m_upBtn.Set(this,TRUE);
  655. m_downBtn.Set(this,FALSE);
  656. BOOL bRes = m_upBtn.SubclassDlgItem(nIDBtnUp, pParentWnd);
  657. ASSERT(bRes);
  658. bRes = m_downBtn.SubclassDlgItem(nIDBtnDown, pParentWnd);
  659. ASSERT(bRes);
  660. if (!bRes) return FALSE;
  661. bRes = m_edit.SubclassDlgItem(nIDEdit, pParentWnd);
  662. ASSERT(bRes);
  663. return bRes;
  664. }
  665. void CDNSUpDownUnsignedIntEditGroup::SetButtonsState()
  666. {
  667. UINT n = m_edit.GetVal();
  668. BOOL bUpEnabled = n < m_edit.GetMax();
  669. BOOL bDownEnabled = n > m_edit.GetMin();
  670. // have to see if buttos get disabled and move the focus accordingly
  671. CWnd* pFocus = CWnd::GetFocus();
  672. CWnd* pNewFocus = pFocus;
  673. if ( (pFocus == &m_upBtn) && !bUpEnabled )
  674. {
  675. pNewFocus = &m_downBtn;
  676. }
  677. if ( (pFocus == &m_downBtn) && !bDownEnabled )
  678. {
  679. pNewFocus = &m_upBtn;
  680. }
  681. if ( ((pFocus == &m_downBtn) || (pFocus == &m_upBtn)) &&
  682. !bDownEnabled && !bUpEnabled )
  683. {
  684. pNewFocus = &m_edit;
  685. }
  686. if (pNewFocus != pFocus)
  687. pNewFocus->SetFocus();
  688. m_upBtn.EnableWindow(bUpEnabled);
  689. m_downBtn.EnableWindow(bDownEnabled);
  690. }
  691. /////////////////////////////////////////////////////////////////////////
  692. // CDNSTimeIntervalEdit
  693. BEGIN_MESSAGE_MAP(CDNSTimeIntervalEdit, CDNSUnsignedIntEdit)
  694. ON_CONTROL_REFLECT(EN_KILLFOCUS, OnKillFocus)
  695. ON_CONTROL_REFLECT(EN_CHANGE, OnChange)
  696. END_MESSAGE_MAP()
  697. void CDNSTimeIntervalEdit::OnKillFocus()
  698. {
  699. m_pEditGroup->OnEditKillFocus();
  700. }
  701. void CDNSTimeIntervalEdit::OnChange()
  702. {
  703. m_pEditGroup->OnEditChange();
  704. }
  705. /////////////////////////////////////////////////////////////////////////
  706. // CDNSTimeUnitComboBox
  707. BEGIN_MESSAGE_MAP(CDNSTimeUnitComboBox, CComboBox)
  708. ON_CONTROL_REFLECT(CBN_SELCHANGE, OnSelChange)
  709. END_MESSAGE_MAP()
  710. void CDNSTimeUnitComboBox::OnSelChange()
  711. {
  712. m_pEditGroup->OnComboSelChange();
  713. }
  714. void CDNSTimeUnitComboBox::SetUnit(unitType u)
  715. {
  716. ASSERT((u >= sec) || (u <= days));
  717. if (GetCount() - 1 < u)
  718. SetCurSel(u - 2);
  719. else
  720. SetCurSel(u);
  721. }
  722. CDNSTimeUnitComboBox::unitType CDNSTimeUnitComboBox::GetUnit()
  723. {
  724. int n = GetCurSel();
  725. unitType u = (unitType)n;
  726. ASSERT((u >= sec) || (u <= days));
  727. return u;
  728. }
  729. BOOL CDNSTimeUnitComboBox::LoadStrings(UINT nIDUnitsString, UINT nMaxAddCount)
  730. {
  731. return LoadStringsToComboBox(_Module.GetModuleInstance(),
  732. this, nIDUnitsString, 256, nMaxAddCount);
  733. }
  734. //////////////////////////////////////////////////////////////////////////
  735. // CDNSTimeIntervalEditGroup
  736. CDNSTimeIntervalEditGroup::CDNSTimeIntervalEditGroup(UINT nMinVal, UINT nMaxVal)
  737. {
  738. m_nMinVal = nMinVal;
  739. m_nMaxVal = nMaxVal;
  740. InitRangeInfo();
  741. }
  742. void CDNSTimeIntervalEditGroup::InitRangeInfo()
  743. {
  744. static UINT _secondsCount[4] =
  745. { 1, 60, 3600, 3600*24 }; // # of secods in a sec, min, hour, day
  746. for (UINT k=0; k<4; k++)
  747. {
  748. if (m_nMinVal == 0)
  749. {
  750. m_rangeInfoArr[k].m_nMinVal = 0;
  751. }
  752. else
  753. {
  754. m_rangeInfoArr[k].m_nMinVal = m_nMinVal/_secondsCount[k];
  755. if (k > 0)
  756. m_rangeInfoArr[k].m_nMinVal++;
  757. }
  758. m_rangeInfoArr[k].m_nMaxVal = m_nMaxVal/_secondsCount[k];
  759. if (m_rangeInfoArr[k].m_nMaxVal >= m_rangeInfoArr[k].m_nMinVal)
  760. m_nRangeCount = k + 1;
  761. }
  762. }
  763. BOOL CDNSTimeIntervalEditGroup::Initialize(CWnd* pParentWnd, UINT nIDEdit,
  764. UINT nIDCombo, UINT nIDComboUnitsString)
  765. {
  766. ASSERT(pParentWnd != NULL);
  767. if (pParentWnd == NULL)
  768. return FALSE;
  769. m_edit.Set(this);
  770. m_timeUnitCombo.Set(this);
  771. BOOL bRes = m_edit.SubclassDlgItem(nIDEdit, pParentWnd);
  772. ASSERT(bRes);
  773. if (!bRes) return FALSE;
  774. bRes = m_timeUnitCombo.SubclassDlgItem(nIDCombo, pParentWnd);
  775. ASSERT(bRes);
  776. if (!bRes) return FALSE;
  777. bRes = m_timeUnitCombo.LoadStrings(nIDComboUnitsString, m_nRangeCount);
  778. return bRes;
  779. }
  780. void CDNSTimeIntervalEditGroup::SetVal(UINT nVal)
  781. {
  782. // set default values
  783. nVal = _ForceToRange(nVal, m_nMinVal, m_nMaxVal);
  784. UINT nMax = (UINT)-1;
  785. CDNSTimeUnitComboBox::unitType u = CDNSTimeUnitComboBox::sec;
  786. // select the best unit of measurement (i.e. no truncation)
  787. if ((nVal/60)*60 == nVal)
  788. {
  789. // can promote to minutes
  790. u = CDNSTimeUnitComboBox::min;
  791. nMax = nMax/60;
  792. nVal = nVal/60;
  793. if ((nVal/60)*60 == nVal)
  794. {
  795. // can promote to hours
  796. u = CDNSTimeUnitComboBox::hrs;
  797. nMax = nMax/60;
  798. nVal = nVal/60;
  799. if ((nVal/24)*24 == nVal)
  800. {
  801. // can promote to days
  802. u = CDNSTimeUnitComboBox::days;
  803. nMax = nMax/24;
  804. nVal = nVal/24;
  805. }
  806. }
  807. }
  808. m_timeUnitCombo.SetUnit(u);
  809. m_edit.SetRange(0,nMax);
  810. m_edit.SetVal(nVal);
  811. }
  812. UINT CDNSTimeIntervalEditGroup::GetVal()
  813. {
  814. UINT nVal = m_edit.GetVal();
  815. CDNSTimeUnitComboBox::unitType u = m_timeUnitCombo.GetUnit();
  816. //
  817. // the value must always to be in seconds
  818. //
  819. if (u != CDNSTimeUnitComboBox::sec)
  820. {
  821. switch(u)
  822. {
  823. case CDNSTimeUnitComboBox::min:
  824. nVal *= 60;
  825. break;
  826. case CDNSTimeUnitComboBox::hrs:
  827. nVal *= 3600;
  828. break;
  829. case CDNSTimeUnitComboBox::days:
  830. nVal *= (3600*24);
  831. break;
  832. default:
  833. ASSERT(FALSE);
  834. }
  835. }
  836. if (nVal < m_nMinVal ||
  837. nVal > m_nMaxVal)
  838. {
  839. UINT nRangeVal = _ForceToRange(nVal, m_nMinVal, m_nMaxVal);
  840. SetVal(nRangeVal);
  841. nVal = nRangeVal;
  842. }
  843. ASSERT(nVal >= m_nMinVal && nVal <= m_nMaxVal);
  844. return nVal;
  845. }
  846. void CDNSTimeIntervalEditGroup::OnEditKillFocus()
  847. {
  848. UINT nVal = m_edit.GetVal();
  849. CDNSTimeUnitComboBox::unitType u = m_timeUnitCombo.GetUnit();
  850. //
  851. // the value must always to be in seconds
  852. //
  853. if (u != CDNSTimeUnitComboBox::sec)
  854. {
  855. switch(u)
  856. {
  857. case CDNSTimeUnitComboBox::min:
  858. nVal *= 60;
  859. break;
  860. case CDNSTimeUnitComboBox::hrs:
  861. nVal *= 3600;
  862. break;
  863. case CDNSTimeUnitComboBox::days:
  864. nVal *= (3600*24);
  865. break;
  866. default:
  867. ASSERT(FALSE);
  868. }
  869. }
  870. UINT nRangeVal = _ForceToRange(nVal, m_nMinVal, m_nMaxVal);
  871. if (nRangeVal != nVal)
  872. {
  873. SetVal(nRangeVal);
  874. }
  875. }
  876. void CDNSTimeIntervalEditGroup::OnComboSelChange()
  877. {
  878. CDNSTimeUnitComboBox::unitType u = m_timeUnitCombo.GetUnit();
  879. // have to adjust the range
  880. UINT nVal = m_edit.GetVal();
  881. UINT nMax = (UINT)-1;
  882. // have to adjust the range
  883. switch(u)
  884. {
  885. case CDNSTimeUnitComboBox::sec:
  886. break;
  887. case CDNSTimeUnitComboBox::min:
  888. nMax /= 60;
  889. break;
  890. case CDNSTimeUnitComboBox::hrs:
  891. nMax /= 3600;
  892. break;
  893. case CDNSTimeUnitComboBox::days:
  894. nMax /= (3600*24);
  895. break;
  896. default:
  897. ASSERT(FALSE);
  898. }
  899. //m_edit.SetRange(0,nMax);
  900. UINT k = (UINT)u;
  901. m_edit.SetRange(m_rangeInfoArr[k].m_nMinVal, m_rangeInfoArr[k].m_nMaxVal);
  902. nVal = _ForceToRange(nVal, m_rangeInfoArr[k].m_nMinVal, m_rangeInfoArr[k].m_nMaxVal);
  903. m_edit.SetVal(nVal);
  904. OnEditChange();
  905. }
  906. void CDNSTimeIntervalEditGroup::EnableUI(BOOL bEnable)
  907. {
  908. m_edit.EnableWindow(bEnable);
  909. m_timeUnitCombo.EnableWindow(bEnable);
  910. }
  911. //////////////////////////////////////////////////////////////////////////
  912. // CDNSManageControlTextHelper
  913. CDNSManageControlTextHelper::CDNSManageControlTextHelper(int nStates)
  914. {
  915. m_nID = 0;
  916. m_pParentWnd = NULL;
  917. ASSERT(nStates > 1);
  918. m_nStates = nStates;
  919. m_lpszText = NULL;
  920. m_lpszArr = (LPWSTR*)malloc(sizeof(LPWSTR*)*m_nStates);
  921. if (m_lpszArr != NULL)
  922. {
  923. memset(m_lpszArr, 0x0, sizeof(LPWSTR*)*m_nStates);
  924. }
  925. }
  926. CDNSManageControlTextHelper::~CDNSManageControlTextHelper()
  927. {
  928. free(m_lpszArr);
  929. if (m_lpszText != NULL)
  930. free(m_lpszText);
  931. }
  932. BOOL CDNSManageControlTextHelper::Init(CWnd* pParentWnd, UINT nID, UINT* nStrArray)
  933. {
  934. ASSERT(m_pParentWnd == NULL);
  935. ASSERT(pParentWnd != NULL);
  936. m_pParentWnd = pParentWnd;
  937. m_nID = nID;
  938. CWnd* pWnd = m_pParentWnd->GetDlgItem(m_nID);
  939. if (pWnd == NULL)
  940. return FALSE;
  941. // get the text out of the window
  942. int nLen = pWnd->GetWindowTextLength();
  943. ASSERT(m_lpszText == NULL);
  944. m_lpszText = (WCHAR*)malloc(sizeof(WCHAR)*(nLen+1));
  945. if (m_lpszText != NULL)
  946. {
  947. pWnd->GetWindowText(m_lpszText, nLen+1);
  948. }
  949. else
  950. {
  951. return FALSE;
  952. }
  953. ASSERT(m_lpszText != NULL);
  954. //
  955. // get the text for the window
  956. //
  957. int nSuccessEntries;
  958. LoadStringArrayFromResource(m_lpszArr, nStrArray, m_nStates, &nSuccessEntries);
  959. ASSERT(nSuccessEntries == m_nStates);
  960. return TRUE;
  961. }
  962. BOOL CDNSManageControlTextHelper::Init(CWnd* pParentWnd, UINT nID)
  963. {
  964. ASSERT(m_pParentWnd == NULL);
  965. ASSERT(pParentWnd != NULL);
  966. m_pParentWnd = pParentWnd;
  967. m_nID = nID;
  968. CWnd* pWnd = m_pParentWnd->GetDlgItem(m_nID);
  969. if (pWnd == NULL)
  970. return FALSE;
  971. //
  972. // get the text out of the window
  973. //
  974. int nLen = pWnd->GetWindowTextLength();
  975. ASSERT(m_lpszText == NULL);
  976. m_lpszText = (WCHAR*)malloc(sizeof(WCHAR)*(nLen+1));
  977. if (m_lpszText != NULL)
  978. {
  979. pWnd->GetWindowText(m_lpszText, nLen+1);
  980. }
  981. else
  982. {
  983. return FALSE;
  984. }
  985. ASSERT(m_lpszText != NULL);
  986. //
  987. // get the text for the window
  988. //
  989. UINT nSuccessEntries;
  990. ParseNewLineSeparatedString(m_lpszText, m_lpszArr, &nSuccessEntries);
  991. ASSERT(nSuccessEntries == (UINT)m_nStates);
  992. return TRUE;
  993. }
  994. void CDNSManageControlTextHelper::SetStateX(int nIndex)
  995. {
  996. CWnd* pWnd = m_pParentWnd->GetDlgItem(m_nID);
  997. ASSERT(pWnd != NULL);
  998. ASSERT( (nIndex >0) || (nIndex < m_nStates));
  999. pWnd->SetWindowText(m_lpszArr[nIndex]);
  1000. }
  1001. //////////////////////////////////////////////////////////////////////////
  1002. // CDNSToggleTextControlHelper
  1003. CDNSToggleTextControlHelper::CDNSToggleTextControlHelper()
  1004. : CDNSManageControlTextHelper(2)
  1005. {
  1006. }
  1007. ///////////////////////////////////////////////////////////////////////////
  1008. // CDNSManageButtonTextHelper
  1009. CDNSManageButtonTextHelper::CDNSManageButtonTextHelper(int nStates)
  1010. {
  1011. m_nID = 0;
  1012. m_pParentWnd = NULL;
  1013. m_nStates = nStates;
  1014. m_lpszText = NULL;
  1015. m_lpszArr = (LPWSTR*)malloc(sizeof(LPWSTR*)*m_nStates);
  1016. if (m_lpszArr != NULL)
  1017. {
  1018. memset(m_lpszArr, 0x0, sizeof(LPWSTR*)*m_nStates);
  1019. }
  1020. }
  1021. CDNSManageButtonTextHelper::~CDNSManageButtonTextHelper()
  1022. {
  1023. for (int k = 0; k < m_nStates; k++)
  1024. {
  1025. if (m_lpszArr[k] != NULL)
  1026. free(m_lpszArr[k]);
  1027. }
  1028. free(m_lpszArr);
  1029. }
  1030. void CDNSManageButtonTextHelper::SetStateX(int nIndex)
  1031. {
  1032. CWnd* pWnd = m_pParentWnd->GetDlgItem(m_nID);
  1033. ASSERT(pWnd != NULL);
  1034. ASSERT( (nIndex >0) || (nIndex < m_nStates));
  1035. pWnd->SetWindowText(m_lpszArr[nIndex]);
  1036. }
  1037. BOOL CDNSManageButtonTextHelper::Init(CWnd* pParentWnd, UINT nButtonID, UINT* nStrArray)
  1038. {
  1039. ASSERT(m_pParentWnd == NULL);
  1040. ASSERT(pParentWnd != NULL);
  1041. m_pParentWnd = pParentWnd;
  1042. m_nID = nButtonID;
  1043. CWnd* pWnd = m_pParentWnd->GetDlgItem(m_nID);
  1044. if (pWnd == NULL)
  1045. return FALSE;
  1046. // get the text for the window
  1047. int nSuccessEntries;
  1048. LoadStringArrayFromResource(m_lpszArr, nStrArray, m_nStates, &nSuccessEntries);
  1049. ASSERT(nSuccessEntries == m_nStates);
  1050. return TRUE;
  1051. }
  1052. ///////////////////////////////////////////////////////////////////////////
  1053. // CDNSButtonToggleTextHelper
  1054. CDNSButtonToggleTextHelper::CDNSButtonToggleTextHelper()
  1055. : CDNSManageButtonTextHelper(2)
  1056. {
  1057. }
  1058. /////////////////////////////////////////////////////////////////////////////
  1059. // CDlgWorkerThread
  1060. CDlgWorkerThread::CDlgWorkerThread()
  1061. {
  1062. m_dwErr = 0x0;
  1063. }
  1064. BOOL CDlgWorkerThread::Start(CLongOperationDialog* pDlg)
  1065. {
  1066. ASSERT(pDlg != NULL);
  1067. HWND hWnd = pDlg->GetSafeHwnd();
  1068. return CWorkerThread::Start(hWnd);
  1069. }
  1070. BOOL CDlgWorkerThread::PostMessageToDlg()
  1071. {
  1072. return PostMessageToWnd(CLongOperationDialog::s_nNotificationMessage,
  1073. (WPARAM)0, (LPARAM)0);
  1074. }
  1075. int CDlgWorkerThread::Run()
  1076. {
  1077. // do the stuff
  1078. OnDoAction();
  1079. VERIFY(PostMessageToDlg());
  1080. WaitForExitAcknowledge();
  1081. //TRACE(_T("exiting\n"));
  1082. return 0;
  1083. }
  1084. /////////////////////////////////////////////////////////////////////////////
  1085. // CLongOperationDialog dialog
  1086. UINT CLongOperationDialog::s_nNotificationMessage = WM_USER + 100;
  1087. CLongOperationDialog::CLongOperationDialog(CDlgWorkerThread* pThreadObj,
  1088. CWnd* pParentWnd,
  1089. UINT nAviID)
  1090. : CDialog(IDD_SEARCHING_DIALOG, pParentWnd)
  1091. {
  1092. ASSERT(pThreadObj != NULL);
  1093. m_bAbandoned = TRUE;
  1094. m_pThreadObj = pThreadObj;
  1095. m_nAviID = nAviID;
  1096. m_bExecuteNoUI = FALSE;
  1097. }
  1098. CLongOperationDialog::~CLongOperationDialog()
  1099. {
  1100. if(m_pThreadObj != NULL)
  1101. {
  1102. delete m_pThreadObj;
  1103. m_pThreadObj = NULL;
  1104. }
  1105. }
  1106. BOOL CLongOperationDialog::LoadTitleString(UINT nID)
  1107. {
  1108. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1109. return m_szTitle.LoadString(nID);
  1110. }
  1111. BEGIN_MESSAGE_MAP(CLongOperationDialog, CDialog)
  1112. ON_MESSAGE( CLongOperationDialog::s_nNotificationMessage, OnNotificationMessage )
  1113. END_MESSAGE_MAP()
  1114. afx_msg LONG CLongOperationDialog::OnNotificationMessage( WPARAM, LPARAM)
  1115. {
  1116. TRACE(_T("CLongOperationDialog::OnNotificationMessage()\n"));
  1117. ASSERT(m_pThreadObj != NULL);
  1118. if (m_pThreadObj != NULL)
  1119. {
  1120. m_pThreadObj->AcknowledgeExiting();
  1121. VERIFY(WAIT_OBJECT_0 == ::WaitForSingleObject(m_pThreadObj->m_hThread,INFINITE));
  1122. m_bAbandoned = FALSE;
  1123. PostMessage(WM_CLOSE,0,0);
  1124. }
  1125. return 0;
  1126. }
  1127. BOOL CLongOperationDialog::OnInitDialog()
  1128. {
  1129. TRACE(_T("CLongOperationDialog::OnInitDialog()\n"));
  1130. CDialog::OnInitDialog();
  1131. if (!m_szTitle.IsEmpty())
  1132. SetWindowText(m_szTitle);
  1133. // load auto play AVI file if needed
  1134. if (m_nAviID != -1)
  1135. {
  1136. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1137. CAnimateCtrl* pAnimate = (CAnimateCtrl*)GetDlgItem(IDC_SEARCH_ANIMATE);
  1138. VERIFY(pAnimate->Open(m_nAviID));
  1139. }
  1140. // spawn worker thread
  1141. GetThreadObj()->Start(this);
  1142. return TRUE;
  1143. }
  1144. void CLongOperationDialog::OnCancel()
  1145. {
  1146. TRACE(_T("CLongOperationDialog::OnCancel()\n"));
  1147. if (m_bAbandoned)
  1148. {
  1149. m_pThreadObj->Abandon();
  1150. m_pThreadObj = NULL;
  1151. }
  1152. CDialog::OnCancel();
  1153. }
  1154. //////////////////////////////////////////////////////////
  1155. // CNodeEnumerationThread
  1156. CNodeEnumerationThread::CNodeEnumerationThread(CComponentDataObject* pComponentDataObject,
  1157. CMTContainerNode* pNode)
  1158. {
  1159. m_pSink = new CNotificationSinkEvent;
  1160. ASSERT(m_pSink != NULL);
  1161. m_pNode = pNode;
  1162. m_pComponentDataObject = pComponentDataObject;
  1163. m_pComponentDataObject->GetNotificationSinkTable()->Advise(m_pSink);
  1164. }
  1165. CNodeEnumerationThread::~CNodeEnumerationThread()
  1166. {
  1167. if (m_pComponentDataObject != NULL)
  1168. m_pComponentDataObject->GetNotificationSinkTable()->Unadvise(m_pSink);
  1169. delete m_pSink;
  1170. }
  1171. void CNodeEnumerationThread::OnDoAction()
  1172. {
  1173. TRACE(_T("CNodeEnumerationThread::OnDoAction() before Wait\n"));
  1174. ASSERT(m_pSink != NULL);
  1175. VERIFY(m_pComponentDataObject->PostForceEnumeration(m_pNode));
  1176. m_pSink->Wait();
  1177. TRACE(_T("CNodeEnumerationThread::OnDoAction() after Wait\n"));
  1178. }
  1179. void CNodeEnumerationThread::OnAbandon()
  1180. {
  1181. ASSERT(m_pComponentDataObject != NULL);
  1182. m_pComponentDataObject->GetNotificationSinkTable()->Unadvise(m_pSink);
  1183. m_pComponentDataObject = NULL;
  1184. }
  1185. //////////////////////////////////////////////////////////
  1186. // CArrayCheckListBox
  1187. BOOL CArrayCheckListBox::Initialize(UINT nCtrlID, UINT nStringID, CWnd* pParentWnd)
  1188. {
  1189. if (!SubclassDlgItem(nCtrlID, pParentWnd))
  1190. return FALSE;
  1191. SetCheckStyle(BS_AUTOCHECKBOX);
  1192. CString szBuf;
  1193. {
  1194. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1195. if (!szBuf.LoadString(nStringID))
  1196. return FALSE;
  1197. }
  1198. LPWSTR* lpszArr = (LPWSTR*)malloc(sizeof(LPWSTR*)*m_nArrSize);
  1199. if (!lpszArr)
  1200. {
  1201. return FALSE;
  1202. }
  1203. UINT nArrEntries;
  1204. ParseNewLineSeparatedString(szBuf.GetBuffer(1),lpszArr, &nArrEntries);
  1205. szBuf.ReleaseBuffer();
  1206. ASSERT(nArrEntries == m_nArrSize);
  1207. for (UINT k=0; k<nArrEntries; k++)
  1208. AddString(lpszArr[k]);
  1209. if (lpszArr)
  1210. {
  1211. free(lpszArr);
  1212. lpszArr = 0;
  1213. }
  1214. return TRUE;
  1215. }
  1216. void CArrayCheckListBox::SetValue(DWORD dw)
  1217. {
  1218. for (UINT i=0; i< m_nArrSize; i++)
  1219. SetCheck(i, (dw & m_dwMaskArr[i]) != 0);
  1220. }
  1221. DWORD CArrayCheckListBox::GetValue()
  1222. {
  1223. DWORD dw = 0;
  1224. for (UINT i=0; i< m_nArrSize; i++)
  1225. dw |= GetCheck(i) ? m_dwMaskArr[i] : 0;
  1226. return dw;
  1227. }
  1228. void CArrayCheckListBox::SetArrValue(DWORD* dwArr, UINT nArrSize)
  1229. {
  1230. ASSERT(nArrSize <= m_nArrSize);
  1231. for (UINT i=0; i< nArrSize; i++)
  1232. SetCheck(i, dwArr[i] != 0);
  1233. }
  1234. void CArrayCheckListBox::GetArrValue(DWORD* dwArr, UINT nArrSize)
  1235. {
  1236. ASSERT(nArrSize <= m_nArrSize);
  1237. for (UINT i=0; i< m_nArrSize; i++)
  1238. dwArr[i] = GetCheck(i) != 0;
  1239. }
  1240. /*
  1241. //////////////////////////////////////////////////////////
  1242. // CDNSNameEditField
  1243. void CDNSNameEditField::SetReadOnly(BOOL bReadOnly)
  1244. {
  1245. // toggle the tabstop flag
  1246. LONG currStyle = ::GetWindowLong(m_edit.m_hWnd, GWL_STYLE);
  1247. LONG newStyle = currStyle;
  1248. if (bReadOnly)
  1249. newStyle &= ~WS_TABSTOP;
  1250. else
  1251. newStyle |= WS_TABSTOP;
  1252. if (newStyle != currStyle) {
  1253. ::SetWindowLong(m_edit.m_hWnd, GWL_STYLE, newStyle);
  1254. }
  1255. // toggle the read only state
  1256. m_edit.SetReadOnly(bReadOnly);
  1257. }
  1258. //////////////////////////////////////////////////////////
  1259. // CDNSNameEditField::CDNSNameEditBox
  1260. BEGIN_MESSAGE_MAP(CDNSNameEditField::CDNSNameEditBox, CEdit)
  1261. ON_CONTROL_REFLECT(EN_UPDATE, CDNSNameEditField::CDNSNameEditBox::OnUpdate)
  1262. END_MESSAGE_MAP()
  1263. void CDNSNameEditField::CDNSNameEditBox::OnUpdate()
  1264. {
  1265. if (m_bUpdatePending)
  1266. return; // avoid infinite loop
  1267. GetWindowText(m_szScratchBuffer);
  1268. TRACE(_T("OnUpdate() Text = <%s>\n"), (LPCWSTR)m_szScratchBuffer);
  1269. DNS_STATUS errName = 0;
  1270. int nScratchBufferLen = m_szScratchBuffer.GetLength();
  1271. int nScratchBufferUTF8Len = UTF8StringLen(m_szScratchBuffer);
  1272. // validate max length
  1273. if ((m_nTextLimit >= 0) && (nScratchBufferUTF8Len > m_nTextLimit))
  1274. {
  1275. errName = -1;
  1276. }
  1277. // validate no dots
  1278. if ((errName == 0) && (m_dwFlags & DNS_NAME_EDIT_FIELD_NODOTS))
  1279. {
  1280. errName = m_szScratchBuffer.Find(L'.') != -1;
  1281. }
  1282. if ((errName == 0) && ((m_dwFlags & DNS_NAME_EDIT_FIELD_NOVALIDATE) == 0))
  1283. {
  1284. errName = Validate(nScratchBufferLen);
  1285. }
  1286. if (errName != 0)
  1287. {
  1288. // bad stuff
  1289. m_bUpdatePending = TRUE;
  1290. int nStartChar, nEndChar;
  1291. GetSel(nStartChar,nEndChar);
  1292. SetWindowText(m_szCurrText);
  1293. SetSel(nStartChar-1,nEndChar-1);
  1294. m_bUpdatePending = FALSE;
  1295. }
  1296. else
  1297. {
  1298. // good stuff
  1299. m_szCurrText = m_szScratchBuffer;
  1300. m_nCurrTextLen = nScratchBufferLen;
  1301. m_nCurrUTF8TextLen = nScratchBufferUTF8Len;
  1302. }
  1303. }
  1304. DNS_STATUS CDNSNameEditField::CDNSNameEditBox::Validate(int nScratchBufferLen)
  1305. {
  1306. DNS_STATUS errName = 0;
  1307. if ((errName == 0) && (nScratchBufferLen > 0))
  1308. {
  1309. // check for wildcards records
  1310. int nFirstAsterisk = m_szScratchBuffer.Find(L'*');
  1311. if (m_dwFlags & DNS_NAME_EDIT_FIELD_NOWILDCARDS)
  1312. {
  1313. // wildcards not accepted
  1314. errName = (nFirstAsterisk != -1);
  1315. }
  1316. else
  1317. {
  1318. if (nFirstAsterisk >= 0) // found at least one
  1319. {
  1320. // string must be "*"
  1321. errName = !((nScratchBufferLen == 1) && (nFirstAsterisk == 0));
  1322. }
  1323. }
  1324. // validate name against RFC
  1325. LPCWSTR lpszName = (LPCWSTR)m_szScratchBuffer;
  1326. if ( (errName == 0) && (m_dwFlags & (DNS_NAME_EDIT_FIELD_NORFC | DNS_NAME_EDIT_FIELD_RFC)) )
  1327. {
  1328. errName = ::DnsValidateName_W(lpszName, DnsNameDomain);
  1329. TRACE(_T("::DnsValidateName_W(%ws) return %d.\n"), lpszName, errName);
  1330. if ((m_dwFlags & DNS_NAME_EDIT_FIELD_NORFC) && (errName == DNS_ERROR_NON_RFC_NAME))
  1331. {
  1332. // we relax RFC compliance
  1333. errName = 0;
  1334. }
  1335. else if ( (m_dwFlags & DNS_NAME_EDIT_FIELD_ALLOWNUMBERS) )
  1336. {
  1337. // Assume the name failed because it is all digits
  1338. BOOL bAllDigits = TRUE;
  1339. LPWSTR lpszBuf = (LPWSTR)(LPCWSTR)m_szScratchBuffer;
  1340. for (int idx = 0; idx < nScratchBufferLen; idx++)
  1341. {
  1342. if (!iswdigit(lpszBuf[idx]))
  1343. {
  1344. // If we run across something that isn't a digit then thats not why we failed.
  1345. bAllDigits = FALSE;
  1346. TRACE(_T("Not all the characters are digits but something is still wrong.\n"));
  1347. }
  1348. }
  1349. if (bAllDigits)
  1350. {
  1351. errName = 0;
  1352. }
  1353. }
  1354. }
  1355. }
  1356. TRACE(_T("CDNSNameEditField::CDNSNameEditBox::Validate returns %d.\n"), errName);
  1357. return errName;
  1358. }
  1359. */
  1360. ////////////////////////////////////////////////////////////////////////////
  1361. // CDNSZone_AgingDialog
  1362. BEGIN_MESSAGE_MAP(CDNSZone_AgingDialog, CHelpDialog)
  1363. ON_BN_CLICKED(IDC_SCAVENGING_ENABLED, OnCheckScavenge)
  1364. END_MESSAGE_MAP()
  1365. CDNSZone_AgingDialog::CDNSZone_AgingDialog(CPropertyPageHolderBase* pHolder, UINT nID, CComponentDataObject* pComponentData)
  1366. : CHelpDialog(nID, pComponentData)
  1367. {
  1368. m_pHolder = pHolder;
  1369. m_bDirty = FALSE;
  1370. m_bAdvancedView = FALSE;
  1371. m_bScavengeDirty = FALSE;
  1372. m_bNoRefreshDirty = FALSE;
  1373. m_bRefreshDirty = FALSE;
  1374. // m_bApplyAll = FALSE;
  1375. m_bADApplyAll = FALSE;
  1376. // m_bStandardApplyAll = FALSE;
  1377. m_dwDefaultRefreshInterval = 0;
  1378. m_dwDefaultNoRefreshInterval = 0;
  1379. m_bDefaultScavengingState = FALSE;
  1380. if (pComponentData != NULL)
  1381. {
  1382. m_pComponentData = pComponentData;
  1383. }
  1384. else
  1385. {
  1386. m_pComponentData = pHolder->GetComponentData();
  1387. }
  1388. }
  1389. BOOL CDNSZone_AgingDialog::OnInitDialog()
  1390. {
  1391. CHelpDialog::OnInitDialog();
  1392. if (m_pHolder != NULL)
  1393. m_pHolder->PushDialogHWnd(GetSafeHwnd());
  1394. m_refreshIntervalEditGroup.m_pPage = this;
  1395. m_norefreshIntervalEditGroup.m_pPage = this;
  1396. VERIFY(m_refreshIntervalEditGroup.Initialize(this,
  1397. IDC_REFR_INT_EDIT1, IDC_REFR_INT_COMBO1,IDS_TIME_AGING_INTERVAL_UNITS));
  1398. VERIFY(m_norefreshIntervalEditGroup.Initialize(this,
  1399. IDC_REFR_INT_EDIT2, IDC_REFR_INT_COMBO2,IDS_TIME_AGING_INTERVAL_UNITS));
  1400. SendDlgItemMessage(IDC_REFR_INT_EDIT1, EM_SETLIMITTEXT, (WPARAM)10, 0);
  1401. SendDlgItemMessage(IDC_REFR_INT_EDIT2, EM_SETLIMITTEXT, (WPARAM)10, 0);
  1402. SetUIData();
  1403. return TRUE;
  1404. }
  1405. void CDNSZone_AgingDialog::SetUIData()
  1406. {
  1407. m_refreshIntervalEditGroup.SetVal(m_dwRefreshInterval);
  1408. m_norefreshIntervalEditGroup.SetVal(m_dwNoRefreshInterval);
  1409. ((CButton*)GetDlgItem(IDC_SCAVENGING_ENABLED))->SetCheck(m_fScavengingEnabled);
  1410. // Enable the time stamp if we are in advanced view and got here through the zone property pages
  1411. if (m_bAdvancedView && m_pHolder != NULL)
  1412. {
  1413. GetDlgItem(IDC_TIME_STAMP_STATIC1)->EnableWindow(TRUE);
  1414. GetDlgItem(IDC_TIME_STAMP_STATIC2)->EnableWindow(TRUE);
  1415. GetDlgItem(IDC_TIME_STAMP)->EnableWindow(TRUE);
  1416. GetDlgItem(IDC_TIME_STAMP_STATIC1)->ShowWindow(TRUE);
  1417. GetDlgItem(IDC_TIME_STAMP_STATIC2)->ShowWindow(TRUE);
  1418. GetDlgItem(IDC_TIME_STAMP)->ShowWindow(TRUE);
  1419. CString cstrDate;
  1420. GetTimeStampString(cstrDate);
  1421. GetDlgItem(IDC_TIME_STAMP)->SetWindowText(cstrDate);
  1422. }
  1423. else if (!m_bAdvancedView && m_pHolder != NULL)
  1424. {
  1425. GetDlgItem(IDC_TIME_STAMP_STATIC1)->EnableWindow(FALSE);
  1426. GetDlgItem(IDC_TIME_STAMP_STATIC2)->EnableWindow(FALSE);
  1427. GetDlgItem(IDC_TIME_STAMP)->EnableWindow(FALSE);
  1428. GetDlgItem(IDC_TIME_STAMP_STATIC1)->ShowWindow(FALSE);
  1429. GetDlgItem(IDC_TIME_STAMP_STATIC2)->ShowWindow(FALSE);
  1430. GetDlgItem(IDC_TIME_STAMP)->ShowWindow(FALSE);
  1431. ((CButton*)GetDlgItem(IDC_SCAVENGING_ENABLED))->SetCheck(m_fScavengingEnabled);
  1432. }
  1433. }
  1434. void CDNSZone_AgingDialog::OnCheckScavenge()
  1435. {
  1436. m_bScavengeDirty = TRUE;
  1437. GetDlgItem(IDOK)->EnableWindow(TRUE);
  1438. }
  1439. void CDNSZone_AgingDialog::SetDirty()
  1440. {
  1441. m_bDirty = TRUE;
  1442. GetDlgItem(IDOK)->EnableWindow(TRUE);
  1443. }
  1444. void CDNSZone_AgingDialog::GetTimeStampString(CString& strref)
  1445. {
  1446. SYSTEMTIME sysUTimeStamp, sysLTimeStamp;
  1447. VERIFY(SUCCEEDED(Dns_SystemHrToSystemTime(m_dwScavengingStart, &sysUTimeStamp)));
  1448. if (!::SystemTimeToTzSpecificLocalTime(NULL, &sysUTimeStamp, &sysLTimeStamp))
  1449. return;
  1450. // Format the string with respect to locale
  1451. PTSTR ptszDate = NULL;
  1452. int cchDate = 0;
  1453. cchDate = GetDateFormat(LOCALE_USER_DEFAULT, 0 ,
  1454. &sysLTimeStamp, NULL,
  1455. ptszDate, 0);
  1456. ptszDate = (PTSTR)malloc(sizeof(TCHAR) * cchDate);
  1457. if (ptszDate == NULL)
  1458. {
  1459. strref = L"";
  1460. return;
  1461. }
  1462. if (GetDateFormat(LOCALE_USER_DEFAULT, 0,
  1463. &sysLTimeStamp, NULL,
  1464. ptszDate, cchDate))
  1465. {
  1466. strref = ptszDate;
  1467. }
  1468. else
  1469. {
  1470. strref = L"";
  1471. }
  1472. free(ptszDate);
  1473. PTSTR ptszTime = NULL;
  1474. cchDate = GetTimeFormat(LOCALE_USER_DEFAULT, 0 ,
  1475. &sysLTimeStamp, NULL,
  1476. ptszTime, 0);
  1477. ptszTime = (PTSTR)malloc(sizeof(TCHAR) * cchDate);
  1478. if (GetTimeFormat(LOCALE_USER_DEFAULT, 0,
  1479. &sysLTimeStamp, NULL,
  1480. ptszTime, cchDate))
  1481. {
  1482. strref += _T(" ") + CString(ptszTime);
  1483. }
  1484. else
  1485. {
  1486. strref += _T("");
  1487. }
  1488. free(ptszTime);
  1489. }
  1490. void CDNSZone_AgingDialog::OnOK()
  1491. {
  1492. if (m_pHolder != NULL)
  1493. m_pHolder->PopDialogHWnd();
  1494. if (m_pHolder == NULL)
  1495. {
  1496. if (0 != m_refreshIntervalEditGroup.GetVal())
  1497. {
  1498. if (m_dwRefreshInterval != m_refreshIntervalEditGroup.GetVal())
  1499. {
  1500. m_dwRefreshInterval = m_refreshIntervalEditGroup.GetVal();
  1501. m_bRefreshDirty = TRUE;
  1502. }
  1503. else
  1504. {
  1505. m_bRefreshDirty = FALSE;
  1506. }
  1507. }
  1508. else
  1509. {
  1510. DNSMessageBox(IDS_MSG_INVALID_REFRESH_INTERVAL);
  1511. return;
  1512. }
  1513. if (0 != m_norefreshIntervalEditGroup.GetVal())
  1514. {
  1515. if (m_dwNoRefreshInterval != m_norefreshIntervalEditGroup.GetVal())
  1516. {
  1517. m_dwNoRefreshInterval = m_norefreshIntervalEditGroup.GetVal();
  1518. m_bNoRefreshDirty = TRUE;
  1519. }
  1520. else
  1521. {
  1522. m_bNoRefreshDirty = FALSE;
  1523. }
  1524. }
  1525. else
  1526. {
  1527. DNSMessageBox(IDS_MSG_INVALID_NOREFRESH_INTERVAL);
  1528. return;
  1529. }
  1530. if (m_fScavengingEnabled != static_cast<DWORD>(((CButton*)GetDlgItem(IDC_SCAVENGING_ENABLED))->GetCheck()))
  1531. {
  1532. m_fScavengingEnabled = ((CButton*)GetDlgItem(IDC_SCAVENGING_ENABLED))->GetCheck();
  1533. m_bScavengeDirty = TRUE;
  1534. }
  1535. else
  1536. {
  1537. m_bScavengeDirty = FALSE;
  1538. }
  1539. CDNSServer_AgingConfirm dlg(this);
  1540. if (IDOK == dlg.DoModal())
  1541. {
  1542. CHelpDialog::OnOK();
  1543. }
  1544. else
  1545. {
  1546. m_bRefreshDirty = FALSE;
  1547. m_bNoRefreshDirty = FALSE;
  1548. m_bScavengeDirty = FALSE;
  1549. m_dwRefreshInterval = m_dwDefaultRefreshInterval;
  1550. m_dwNoRefreshInterval = m_dwDefaultNoRefreshInterval;
  1551. m_fScavengingEnabled = m_bDefaultScavengingState;
  1552. SetUIData();
  1553. }
  1554. }
  1555. else
  1556. {
  1557. BOOL bContinue = TRUE;
  1558. if (!((CDNSZoneNode*)m_pHolder->GetTreeNode())->IsDSIntegrated() &&
  1559. ((CButton*)GetDlgItem(IDC_SCAVENGING_ENABLED))->GetCheck() &&
  1560. !m_fScavengingEnabled)
  1561. {
  1562. if (DNSMessageBox(IDS_MSG_FILE_WARNING_ZONE, MB_YESNO) == IDNO)
  1563. {
  1564. bContinue = FALSE;
  1565. }
  1566. }
  1567. if (bContinue)
  1568. {
  1569. if (0 != m_refreshIntervalEditGroup.GetVal())
  1570. {
  1571. if (m_dwRefreshInterval != m_refreshIntervalEditGroup.GetVal())
  1572. {
  1573. m_dwRefreshInterval = m_refreshIntervalEditGroup.GetVal();
  1574. m_bRefreshDirty = TRUE;
  1575. }
  1576. else
  1577. {
  1578. m_bRefreshDirty = FALSE;
  1579. }
  1580. }
  1581. else
  1582. {
  1583. DNSMessageBox(IDS_MSG_INVALID_REFRESH_INTERVAL);
  1584. return;
  1585. }
  1586. if (0 != m_norefreshIntervalEditGroup.GetVal())
  1587. {
  1588. if (m_dwNoRefreshInterval != m_norefreshIntervalEditGroup.GetVal())
  1589. {
  1590. m_dwNoRefreshInterval = m_norefreshIntervalEditGroup.GetVal();
  1591. m_bNoRefreshDirty = TRUE;
  1592. }
  1593. else
  1594. {
  1595. m_bNoRefreshDirty = FALSE;
  1596. }
  1597. }
  1598. else
  1599. {
  1600. DNSMessageBox(IDS_MSG_INVALID_NOREFRESH_INTERVAL);
  1601. return;
  1602. }
  1603. if (m_fScavengingEnabled != static_cast<DWORD>(((CButton*)GetDlgItem(IDC_SCAVENGING_ENABLED))->GetCheck()))
  1604. {
  1605. m_fScavengingEnabled = ((CButton*)GetDlgItem(IDC_SCAVENGING_ENABLED))->GetCheck();
  1606. m_bScavengeDirty = TRUE;
  1607. }
  1608. else
  1609. {
  1610. m_bScavengeDirty = FALSE;
  1611. }
  1612. }
  1613. CHelpDialog::OnOK();
  1614. }
  1615. }
  1616. void CDNSZone_AgingDialog::OnCancel()
  1617. {
  1618. if (m_pHolder != NULL)
  1619. m_pHolder->PopDialogHWnd();
  1620. CHelpDialog::OnCancel();
  1621. }
  1622. ////////////////////////////////////////////////////////////////////////////
  1623. // CDNS_AGING_TimeIntervalEditGroup
  1624. void CDNS_AGING_TimeIntervalEditGroup::OnEditChange()
  1625. {
  1626. if (m_pPage != NULL)
  1627. m_pPage->SetDirty();
  1628. }
  1629. // REVIEW_JEFFJON : Both of these functions are some serious hacks and need to be fixed
  1630. // These hacks were put in to deal with a combo box that only has hours
  1631. // and days, instead of seconds, minutes, hours, and days.
  1632. void CDNS_AGING_TimeIntervalEditGroup::SetVal(UINT nVal)
  1633. {
  1634. // set default values
  1635. nVal = _ForceToRange(nVal, m_nMinVal, m_nMaxVal);
  1636. UINT nMax = (UINT)-1;
  1637. CDNSTimeUnitComboBox::unitType u = CDNSTimeUnitComboBox::hrs;
  1638. if ((nVal/24)*24 == nVal)
  1639. {
  1640. // can promote to days
  1641. u = CDNSTimeUnitComboBox::days;
  1642. nMax = nMax/24;
  1643. nVal = nVal/24;
  1644. }
  1645. m_timeUnitCombo.SetUnit(u);
  1646. m_edit.SetRange(0,nMax);
  1647. m_edit.SetVal(nVal);
  1648. }
  1649. UINT CDNS_AGING_TimeIntervalEditGroup::GetVal()
  1650. {
  1651. CDNSTimeUnitComboBox::unitType u = m_timeUnitCombo.GetUnit();
  1652. UINT nVal = m_edit.GetVal();
  1653. // the value must always to be in hours
  1654. if (u != CDNSTimeUnitComboBox::sec)
  1655. {
  1656. switch(u)
  1657. {
  1658. case CDNSTimeUnitComboBox::min:
  1659. nVal *= 24;
  1660. break;
  1661. default:
  1662. ASSERT(FALSE);
  1663. }
  1664. }
  1665. ASSERT(nVal >= m_nMinVal && nVal <= m_nMaxVal);
  1666. return nVal;
  1667. }
  1668. void CDNS_AGING_TimeIntervalEditGroup::InitRangeInfo()
  1669. {
  1670. static UINT _secondsCount[2] =
  1671. { 1, 24 }; // # of hours in a hour, day
  1672. for (UINT k=0; k<2; k++)
  1673. {
  1674. if (m_nMinVal == 0)
  1675. {
  1676. m_rangeInfoArr[k].m_nMinVal = 0;
  1677. }
  1678. else
  1679. {
  1680. m_rangeInfoArr[k].m_nMinVal = m_nMinVal/_secondsCount[k];
  1681. if (k > 0)
  1682. m_rangeInfoArr[k].m_nMinVal++;
  1683. }
  1684. m_rangeInfoArr[k].m_nMaxVal = m_nMaxVal/_secondsCount[k];
  1685. if (m_rangeInfoArr[k].m_nMaxVal >= m_rangeInfoArr[k].m_nMinVal)
  1686. m_nRangeCount = k + 1;
  1687. }
  1688. }
  1689. void CDNS_SERVER_AGING_TimeIntervalEditGroup::OnEditChange()
  1690. {
  1691. if (m_pPage2 != NULL)
  1692. m_pPage2->SetDirty(TRUE);
  1693. }
  1694. ////////////////////////////////////////////////////////////////////////////////////
  1695. // CDNSServer_AgingConfirm
  1696. BOOL CDNSServer_AgingConfirm::OnInitDialog()
  1697. {
  1698. CHelpDialog::OnInitDialog();
  1699. // Removed because we didn't want to expose the defaults for file based zones
  1700. // ((CButton*)GetDlgItem(IDC_CHECK_AD))->SetCheck(TRUE);
  1701. // ((CButton*)GetDlgItem(IDC_CHECK_AD))->EnableWindow(FALSE);
  1702. SetAgingUpdateValues();
  1703. return FALSE;
  1704. }
  1705. void CDNSServer_AgingConfirm::SetAgingUpdateValues()
  1706. {
  1707. CEdit* pcAgingProps = (CEdit*)GetDlgItem(IDC_EDIT_NEW_DEFAULTS);
  1708. ASSERT(pcAgingProps != NULL);
  1709. CString szScavengeFormat, szScavengeValue,
  1710. szRefreshFormat, szRefreshValue,
  1711. szNoRefreshFormat, szNoRefreshValue,
  1712. szTotalString;
  1713. if (m_pAgingDialog->m_bScavengeDirty)
  1714. {
  1715. CString szEnabled;
  1716. VERIFY(szScavengeFormat.LoadString(IDS_SERVER_SCAVENGE_FORMAT));
  1717. if (m_pAgingDialog->m_fScavengingEnabled)
  1718. {
  1719. VERIFY(szEnabled.LoadString(IDS_ENABLED));
  1720. }
  1721. else
  1722. {
  1723. VERIFY(szEnabled.LoadString(IDS_DISABLED));
  1724. }
  1725. szScavengeValue.Format(szScavengeFormat, szEnabled);
  1726. szTotalString += szScavengeValue + _T("\r\n");
  1727. }
  1728. if (m_pAgingDialog->m_bNoRefreshDirty)
  1729. {
  1730. CString szUnit;
  1731. VERIFY(szNoRefreshFormat.LoadString(IDS_SERVER_NO_REFRESH_FORMAT));
  1732. DWORD nVal = 0;
  1733. if (m_pAgingDialog->m_dwNoRefreshInterval % 24 == 0)
  1734. {
  1735. szUnit.LoadString(IDS_DAYS);
  1736. nVal = m_pAgingDialog->m_dwNoRefreshInterval / 24;
  1737. }
  1738. else
  1739. {
  1740. szUnit.LoadString(IDS_HOURS);
  1741. nVal = m_pAgingDialog->m_dwNoRefreshInterval;
  1742. }
  1743. szNoRefreshValue.Format(szNoRefreshFormat, nVal, szUnit);
  1744. szTotalString += szNoRefreshValue + _T("\r\n");
  1745. }
  1746. if (m_pAgingDialog->m_bRefreshDirty)
  1747. {
  1748. CString szUnit;
  1749. VERIFY(szRefreshFormat.LoadString(IDS_SERVER_REFRESH_FORMAT));
  1750. DWORD nVal = 0;
  1751. if (m_pAgingDialog->m_dwRefreshInterval % 24 == 0)
  1752. {
  1753. szUnit.LoadString(IDS_DAYS);
  1754. nVal = m_pAgingDialog->m_dwRefreshInterval / 24;
  1755. }
  1756. else
  1757. {
  1758. szUnit.LoadString(IDS_HOURS);
  1759. nVal = m_pAgingDialog->m_dwRefreshInterval;
  1760. }
  1761. szRefreshValue.Format(szRefreshFormat, nVal, szUnit);
  1762. szTotalString += szRefreshValue;
  1763. }
  1764. pcAgingProps->SetWindowText(szTotalString);
  1765. }
  1766. void CDNSServer_AgingConfirm::OnOK()
  1767. {
  1768. // Removed because we didn't want to expose the defaults for file based zones
  1769. /* if (((CButton*)GetDlgItem(IDC_CHECK_STANDARD))->GetCheck() && m_pAgingDialog->m_fScavengingEnabled)
  1770. {
  1771. if (DNSMessageBox(IDS_MSG_FILE_WARNING, MB_YESNO) == IDNO)
  1772. {
  1773. return;
  1774. }
  1775. }
  1776. */
  1777. m_pAgingDialog->m_bADApplyAll = ((CButton*)GetDlgItem(IDC_CHECK_AD_APPLY_ALL))->GetCheck();
  1778. // Removed because we didn't want to expose the defaults for file based zones
  1779. // m_pAgingDialog->m_bADApplyAll = ((CButton*)GetDlgItem(IDC_CHECK_AD))->GetCheck();
  1780. // m_pAgingDialog->m_bStandardApplyAll = ((CButton*)GetDlgItem(IDC_CHECK_STANDARD))->GetCheck();
  1781. CHelpDialog::OnOK();
  1782. }
  1783. ///////////////////////////////////////////////////////////////////////////////
  1784. BOOL
  1785. WINAPI
  1786. DNSTzSpecificLocalTimeToSystemTime(
  1787. LPTIME_ZONE_INFORMATION lpTimeZoneInformation,
  1788. LPSYSTEMTIME lpLocalTime,
  1789. LPSYSTEMTIME lpUniversalTime
  1790. )
  1791. {
  1792. TIME_ZONE_INFORMATION TziData;
  1793. LPTIME_ZONE_INFORMATION Tzi;
  1794. RTL_TIME_ZONE_INFORMATION tzi;
  1795. LARGE_INTEGER TimeZoneBias;
  1796. LARGE_INTEGER NewTimeZoneBias;
  1797. LARGE_INTEGER LocalCustomBias;
  1798. LARGE_INTEGER StandardTime;
  1799. LARGE_INTEGER DaylightTime;
  1800. LARGE_INTEGER CurrentLocalTime;
  1801. LARGE_INTEGER ComputedUniversalTime;
  1802. ULONG CurrentTimeZoneId = 0xffffffff;
  1803. //
  1804. // Get the timezone information into a useful format
  1805. //
  1806. if ( !ARGUMENT_PRESENT(lpTimeZoneInformation) ) {
  1807. //
  1808. // Convert universal time to local time using current timezone info
  1809. //
  1810. if (GetTimeZoneInformation(&TziData) == TIME_ZONE_ID_INVALID) {
  1811. return FALSE;
  1812. }
  1813. Tzi = &TziData;
  1814. }
  1815. else {
  1816. Tzi = lpTimeZoneInformation;
  1817. }
  1818. tzi.Bias = Tzi->Bias;
  1819. tzi.StandardBias = Tzi->StandardBias;
  1820. tzi.DaylightBias = Tzi->DaylightBias;
  1821. RtlMoveMemory(&tzi.StandardName,&Tzi->StandardName,sizeof(tzi.StandardName));
  1822. RtlMoveMemory(&tzi.DaylightName,&Tzi->DaylightName,sizeof(tzi.DaylightName));
  1823. tzi.StandardStart.Year = Tzi->StandardDate.wYear ;
  1824. tzi.StandardStart.Month = Tzi->StandardDate.wMonth ;
  1825. tzi.StandardStart.Weekday = Tzi->StandardDate.wDayOfWeek ;
  1826. tzi.StandardStart.Day = Tzi->StandardDate.wDay ;
  1827. tzi.StandardStart.Hour = Tzi->StandardDate.wHour ;
  1828. tzi.StandardStart.Minute = Tzi->StandardDate.wMinute ;
  1829. tzi.StandardStart.Second = Tzi->StandardDate.wSecond ;
  1830. tzi.StandardStart.Milliseconds = Tzi->StandardDate.wMilliseconds;
  1831. tzi.DaylightStart.Year = Tzi->DaylightDate.wYear ;
  1832. tzi.DaylightStart.Month = Tzi->DaylightDate.wMonth ;
  1833. tzi.DaylightStart.Weekday = Tzi->DaylightDate.wDayOfWeek ;
  1834. tzi.DaylightStart.Day = Tzi->DaylightDate.wDay ;
  1835. tzi.DaylightStart.Hour = Tzi->DaylightDate.wHour ;
  1836. tzi.DaylightStart.Minute = Tzi->DaylightDate.wMinute ;
  1837. tzi.DaylightStart.Second = Tzi->DaylightDate.wSecond ;
  1838. tzi.DaylightStart.Milliseconds = Tzi->DaylightDate.wMilliseconds;
  1839. //
  1840. // convert the input local time to NT style time
  1841. //
  1842. if ( !SystemTimeToFileTime(lpLocalTime,(LPFILETIME)&CurrentLocalTime) ) {
  1843. return FALSE;
  1844. }
  1845. //
  1846. // Get the new timezone bias
  1847. //
  1848. NewTimeZoneBias.QuadPart = Int32x32To64(tzi.Bias*60, 10000000);
  1849. //
  1850. // Now see if we have stored cutover times
  1851. //
  1852. if ( tzi.StandardStart.Month && tzi.DaylightStart.Month ) {
  1853. //
  1854. // We have timezone cutover information. Compute the
  1855. // cutover dates and compute what our current bias
  1856. // is
  1857. //
  1858. if ( !RtlCutoverTimeToSystemTime(
  1859. &tzi.StandardStart,
  1860. &StandardTime,
  1861. &CurrentLocalTime,
  1862. TRUE
  1863. ) ) {
  1864. return FALSE;
  1865. }
  1866. if ( !RtlCutoverTimeToSystemTime(
  1867. &tzi.DaylightStart,
  1868. &DaylightTime,
  1869. &CurrentLocalTime,
  1870. TRUE
  1871. ) ) {
  1872. return FALSE;
  1873. }
  1874. //
  1875. // If daylight < standard, then time >= daylight and
  1876. // less than standard is daylight
  1877. //
  1878. if ( DaylightTime.QuadPart < StandardTime.QuadPart ) {
  1879. //
  1880. // If today is >= DaylightTime and < StandardTime, then
  1881. // We are in daylight savings time
  1882. //
  1883. if ( (CurrentLocalTime.QuadPart >= DaylightTime.QuadPart) &&
  1884. (CurrentLocalTime.QuadPart < StandardTime.QuadPart) ) {
  1885. CurrentTimeZoneId = TIME_ZONE_ID_DAYLIGHT;
  1886. }
  1887. else {
  1888. CurrentTimeZoneId = TIME_ZONE_ID_STANDARD;
  1889. }
  1890. }
  1891. else {
  1892. //
  1893. // If today is >= StandardTime and < DaylightTime, then
  1894. // We are in standard time
  1895. //
  1896. if ( (CurrentLocalTime.QuadPart >= StandardTime.QuadPart ) &&
  1897. (CurrentLocalTime.QuadPart < DaylightTime.QuadPart ) ) {
  1898. CurrentTimeZoneId = TIME_ZONE_ID_STANDARD;
  1899. }
  1900. else {
  1901. CurrentTimeZoneId = TIME_ZONE_ID_DAYLIGHT;
  1902. }
  1903. }
  1904. //
  1905. // At this point, we know our current timezone and the
  1906. // local time of the next cutover.
  1907. //
  1908. LocalCustomBias.QuadPart = Int32x32To64(
  1909. CurrentTimeZoneId == TIME_ZONE_ID_DAYLIGHT ?
  1910. tzi.DaylightBias*60 :
  1911. tzi.StandardBias*60, // Bias in seconds
  1912. 10000000
  1913. );
  1914. TimeZoneBias.QuadPart = NewTimeZoneBias.QuadPart + LocalCustomBias.QuadPart;
  1915. }
  1916. else {
  1917. TimeZoneBias = NewTimeZoneBias;
  1918. }
  1919. ComputedUniversalTime.QuadPart = CurrentLocalTime.QuadPart + TimeZoneBias.QuadPart;
  1920. if ( !FileTimeToSystemTime((LPFILETIME)&ComputedUniversalTime,lpUniversalTime) ) {
  1921. return FALSE;
  1922. }
  1923. return TRUE;
  1924. }
  1925. LONGLONG
  1926. GetSystemTime64(
  1927. SYSTEMTIME* pSysTime
  1928. )
  1929. /*++
  1930. Function : GetLongSystemTime
  1931. Description:
  1932. Parameters :
  1933. Return : 0 on error, GetLastError for more
  1934. Remarks :
  1935. --*/
  1936. {
  1937. LONGLONG llTime=0;
  1938. LONGLONG llHigh=0;
  1939. FILETIME fileTime;
  1940. //
  1941. // No return checking cause we return 0 on error
  1942. //
  1943. SystemTimeToFileTime( pSysTime, &fileTime );
  1944. llTime = (LONGLONG) fileTime.dwLowDateTime;
  1945. llHigh = (LONGLONG) fileTime.dwHighDateTime;
  1946. llTime |= (llHigh << 32);
  1947. // this is 100ns blocks since 1601. Now convert to seconds
  1948. llTime = llTime / (10*1000*1000L);
  1949. return llTime;
  1950. }
  1951. /////////////////////////////////////////////////////////////////////////
  1952. BOOL LoadComboBoxFromTable(CComboBox* pComboBox, PCOMBOBOX_TABLE_ENTRY pTable)
  1953. {
  1954. BOOL bRet = TRUE;
  1955. if (pComboBox == NULL ||
  1956. pTable == NULL)
  1957. {
  1958. return FALSE;
  1959. }
  1960. PCOMBOBOX_TABLE_ENTRY pTableEntry = pTable;
  1961. while (pTableEntry->nComboStringID != 0)
  1962. {
  1963. CString szComboString;
  1964. if (!szComboString.LoadString(pTableEntry->nComboStringID))
  1965. {
  1966. bRet = FALSE;
  1967. break;
  1968. }
  1969. int idx = pComboBox->AddString(szComboString);
  1970. if (idx != CB_ERR)
  1971. {
  1972. pComboBox->SetItemData(idx, pTableEntry->dwComboData);
  1973. }
  1974. else
  1975. {
  1976. bRet = FALSE;
  1977. break;
  1978. }
  1979. pTableEntry++;
  1980. }
  1981. return bRet;
  1982. }
  1983. BOOL SetComboSelByData(CComboBox* pComboBox, DWORD dwData)
  1984. {
  1985. BOOL bRet = FALSE;
  1986. int iCount = pComboBox->GetCount();
  1987. for (int idx = 0; idx < iCount; idx++)
  1988. {
  1989. if (pComboBox->GetItemData(idx) == dwData)
  1990. {
  1991. pComboBox->SetCurSel(idx);
  1992. bRet = TRUE;
  1993. break;
  1994. }
  1995. }
  1996. return bRet;
  1997. }