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.

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