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.

700 lines
16 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: uiutil.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef __UIUTIL_H
  11. #define __UIUTIL_H
  12. #include "resource.h"
  13. extern "C"
  14. {
  15. #include "maskctrl.h"
  16. }
  17. ///////////////////////////////////////////////////////////////////////////////
  18. // FORWARD DECLARATIONS
  19. class CComponentDataObject;
  20. class CMTContainerNode;
  21. class CNotificationSinkEvent;
  22. /////////////////////////////////////////////////////////////////////////////
  23. typedef enum
  24. {
  25. RECORD_FOUND,
  26. RECORD_NOT_FOUND,
  27. RECORD_NOT_FOUND_AT_THE_NODE,
  28. DOMAIN_NOT_ENUMERATED,
  29. NON_EXISTENT_SUBDOMAIN
  30. } RECORD_SEARCH;
  31. #define ARRAYLENGTH(x) (sizeof(x)/sizeof((x)[0]))
  32. ////////////////////////////////////////////////////////////////////////////
  33. // CDNSNameTokenizer
  34. class CDNSNameTokenizer : public CStringList
  35. {
  36. public:
  37. CDNSNameTokenizer(PCWSTR pszDNSName);
  38. ~CDNSNameTokenizer();
  39. BOOL Tokenize(const wchar_t* wcToken);
  40. void RemoveMatchingFromTail(CDNSNameTokenizer& refTokenizer);
  41. void GetRemaining(CString& strrefRemaining, const wchar_t* wcToken);
  42. private:
  43. CDNSNameTokenizer(const CDNSNameTokenizer&) {}
  44. CDNSNameTokenizer& operator=(const CDNSNameTokenizer&) {}
  45. CString m_szDNSName;
  46. };
  47. ////////////////////////////////////////////////////////////////////////////
  48. // Global functions
  49. BOOL LoadStringsToComboBox(HINSTANCE hInstance, CComboBox* pCombo,
  50. UINT nStringID, UINT nMaxLen, UINT nMaxAddCount);
  51. void ParseNewLineSeparatedString(LPWSTR lpsz,
  52. LPWSTR* lpszArr,
  53. UINT* pnArrEntries);
  54. void LoadStringArrayFromResource(LPWSTR* lpszArr,
  55. UINT* nStringIDs,
  56. int nArrEntries,
  57. int* pnSuccessEntries);
  58. void EnumerateMTNodeHelper(CMTContainerNode* pNode,
  59. CComponentDataObject* pComponentData);
  60. void EnableDialogControls(HWND hWnd, BOOL bEnable);
  61. BOOL LoadFontInfoFromResource(IN UINT nFontNameID,
  62. IN UINT nFontSizeID,
  63. OUT LPWSTR lpFontName, IN int nFontNameMaxchar,
  64. OUT int& nFontSize,
  65. IN LPCWSTR lpszDefaultFont, IN int nDefaultFontSize);
  66. void SetBigBoldFont(HWND hWndDialog, int nControlID);
  67. int GetCheckedRadioButtonHelper(HWND hDlg, int nCount, int* nRadioArr, int nRadioDefault);
  68. UINT _ForceToRange(UINT nVal, UINT nMin, UINT nMax);
  69. BOOL
  70. WINAPI
  71. DNSTzSpecificLocalTimeToSystemTime(
  72. LPTIME_ZONE_INFORMATION lpTimeZoneInformation,
  73. LPSYSTEMTIME lpLocalTime,
  74. LPSYSTEMTIME lpUniversalTime
  75. );
  76. LONGLONG
  77. GetSystemTime64(
  78. SYSTEMTIME* pSysTime
  79. );
  80. ////////////////////////////////////////////////////////////////////////////
  81. // CMultiselectErrorDialog
  82. class CMultiselectErrorDialog : public CDialog
  83. {
  84. public:
  85. CMultiselectErrorDialog() : m_pErrorArray(NULL), CDialog(IDD_MULTISELECT_ERROR_DIALOG) {}
  86. ~CMultiselectErrorDialog() {}
  87. HRESULT Initialize(CNodeList* pNodeList,
  88. DNS_STATUS* pErrorArray,
  89. UINT nErrorCount,
  90. PCWSTR pszTitle,
  91. PCWSTR pszCaption,
  92. PCWSTR pszHeader);
  93. private:
  94. CMultiselectErrorDialog(const CMultiselectErrorDialog&) {}
  95. CMultiselectErrorDialog& operator=(const CMultiselectErrorDialog&) {}
  96. public:
  97. virtual BOOL OnInitDialog();
  98. DECLARE_MESSAGE_MAP()
  99. private:
  100. CNodeList* m_pNodeList;
  101. DNS_STATUS* m_pErrorArray;
  102. UINT m_nErrorCount;
  103. CString m_szTitle;
  104. CString m_szCaption;
  105. CString m_szColumnHeader;
  106. };
  107. ////////////////////////////////////////////////////////////////////////////
  108. // CDNSMaskCtrl
  109. class CDNSMaskCtrl : public CWnd
  110. {
  111. public:
  112. CDNSMaskCtrl() { }
  113. virtual ~CDNSMaskCtrl() {}
  114. public:
  115. BOOL IsBlank();
  116. void SetFocusField(DWORD dwField);
  117. void SetFieldRange(DWORD dwField, DWORD dwMin, DWORD dwMax);
  118. void SetArray(DWORD* pArray, UINT nFields);
  119. void GetArray(DWORD* pArray, UINT nFields);
  120. void Clear(int nField = -1);
  121. void SetAlertFunction( int (*lpfnAlert)(HWND, DWORD, DWORD, DWORD) );
  122. void EnableField(int nField, BOOL bEnable);
  123. static int AlertFunc(HWND hwndParent, DWORD dwCurrent, DWORD dwLow, DWORD dwHigh);
  124. };
  125. ////////////////////////////////////////////////////////////////////////////
  126. // CDNSIPv4Control
  127. class CDNSIPv4Control : public CDNSMaskCtrl
  128. {
  129. public:
  130. CDNSIPv4Control()
  131. {
  132. }
  133. ~CDNSIPv4Control()
  134. {
  135. }
  136. void SetIPv4Val(DWORD x);
  137. void GetIPv4Val(DWORD* pX);
  138. BOOL IsEmpty();
  139. };
  140. ////////////////////////////////////////////////////////////////////////////
  141. // CDNSIPv6Control
  142. class CDNSIPv6Control : public CDNSMaskCtrl
  143. {
  144. public:
  145. // assume the format is a WORD[8] array
  146. void SetIPv6Val(IPV6_ADDRESS* pIpv6Address);
  147. void GetIPv6Val(IPV6_ADDRESS* pIpv6Address);
  148. };
  149. ////////////////////////////////////////////////////////////////////////////
  150. // CDNSTTLControl
  151. class CDNSTTLControl : public CDNSMaskCtrl
  152. {
  153. public:
  154. void SetTTL(DWORD x);
  155. void GetTTL(DWORD* pX);
  156. };
  157. ///////////////////////////////////////////////////////////////////////
  158. // CDNSUnsignedIntEdit
  159. // NOTE: the resource must be an editbox with Numeric Style
  160. class CDNSUnsignedIntEdit : public CEdit
  161. {
  162. public:
  163. CDNSUnsignedIntEdit() {}
  164. BOOL SetVal(UINT nVal);
  165. UINT GetVal();
  166. void SetRange(UINT nMin, UINT nMax)
  167. { m_nMin = nMin; m_nMax = nMax;}
  168. UINT GetMax() { return m_nMax;}
  169. UINT GetMin() { return m_nMin;}
  170. protected:
  171. afx_msg void OnKillFocus();
  172. private:
  173. UINT m_nMin;
  174. UINT m_nMax;
  175. DECLARE_MESSAGE_MAP()
  176. };
  177. ///////////////////////////////////////////////////////////////////////
  178. // CDNSUpDownUnsignedIntEdit
  179. class CDNSUpDownUnsignedIntEditGroup; // fwd decl
  180. class CDNSUpDownUnsignedIntEdit : public CDNSUnsignedIntEdit
  181. {
  182. public:
  183. CDNSUpDownUnsignedIntEdit() { m_pEditGroup = NULL; }
  184. void Set(CDNSUpDownUnsignedIntEditGroup* pEditGroup) { m_pEditGroup = pEditGroup;}
  185. protected:
  186. afx_msg void OnKillFocus();
  187. afx_msg void OnChange();
  188. private:
  189. CDNSUpDownUnsignedIntEditGroup* m_pEditGroup;
  190. DECLARE_MESSAGE_MAP()
  191. };
  192. //////////////////////////////////////////////////////////////////////////
  193. // CDNSUpDownButton
  194. class CDNSUpDownButton : public CButton
  195. {
  196. public:
  197. CDNSUpDownButton() { m_pEditGroup = NULL; m_bUp = TRUE; }
  198. void Set(CDNSUpDownUnsignedIntEditGroup* pEditGroup, BOOL bUp)
  199. { m_pEditGroup = pEditGroup; m_bUp = bUp; }
  200. protected:
  201. afx_msg void OnClicked();
  202. private:
  203. CDNSUpDownUnsignedIntEditGroup* m_pEditGroup;
  204. BOOL m_bUp;
  205. DECLARE_MESSAGE_MAP()
  206. };
  207. //////////////////////////////////////////////////////////////////////////
  208. // CDNSUpDownUnsignedIntEditGroup
  209. class CDNSUpDownUnsignedIntEditGroup
  210. {
  211. public:
  212. CDNSUpDownUnsignedIntEditGroup() {}
  213. BOOL Initialize(CWnd* pParentWnd, UINT nIDEdit,
  214. UINT nIDBtnUp, UINT nIDBtnDown);
  215. void SetRange(UINT nMin, UINT nMax)
  216. { m_edit.SetRange(nMin, nMax); }
  217. void SetVal(UINT nVal);
  218. UINT GetVal();
  219. protected:
  220. virtual void OnEditChange() {}
  221. private:
  222. CDNSUpDownUnsignedIntEdit m_edit;
  223. CDNSUpDownButton m_downBtn;
  224. CDNSUpDownButton m_upBtn;
  225. void SetButtonsState();
  226. void OnClicked(BOOL bUp);
  227. friend class CDNSUpDownButton;
  228. friend class CDNSUpDownUnsignedIntEdit;
  229. };
  230. /////////////////////////////////////////////////////////////////////////
  231. // CDNSTimeIntervalEdit
  232. class CDNSTimeIntervalEditGroup; // fwd decl
  233. class CDNSTimeIntervalEdit : public CDNSUnsignedIntEdit
  234. {
  235. public:
  236. CDNSTimeIntervalEdit() { m_pEditGroup = NULL; }
  237. void Set(CDNSTimeIntervalEditGroup* pEditGroup)
  238. { m_pEditGroup = pEditGroup; }
  239. protected:
  240. afx_msg void OnChange();
  241. afx_msg void OnKillFocus();
  242. private:
  243. CDNSTimeIntervalEditGroup* m_pEditGroup;
  244. DECLARE_MESSAGE_MAP()
  245. };
  246. /////////////////////////////////////////////////////////////////////////
  247. // CDNSTimeUnitComboBox
  248. class CDNSTimeUnitComboBox : public CComboBox
  249. {
  250. public:
  251. typedef enum { sec=0, min, hrs, days} unitType;
  252. CDNSTimeUnitComboBox() { m_pEditGroup = NULL;}
  253. void Set(CDNSTimeIntervalEditGroup* pEditGroup)
  254. { m_pEditGroup = pEditGroup; }
  255. BOOL LoadStrings(UINT nIDUnitsString, UINT nMaxAddCount);
  256. void SetUnit(unitType u);
  257. unitType GetUnit();
  258. protected:
  259. afx_msg void OnSelChange();
  260. private:
  261. CDNSTimeIntervalEditGroup* m_pEditGroup;
  262. DECLARE_MESSAGE_MAP()
  263. };
  264. //////////////////////////////////////////////////////////////////////////
  265. // CDNSTimeIntervalEditGroup
  266. class CDNSTimeIntervalEditGroup
  267. {
  268. public:
  269. CDNSTimeIntervalEditGroup(UINT nMinVal = 0 , UINT nMaxVal = (UINT)-1);
  270. BOOL Initialize(CWnd* pParentWnd, UINT nIDEdit,
  271. UINT nIDCombo, UINT nIDComboUnitsString);
  272. void SetVal(UINT nVal);
  273. UINT GetVal();
  274. void EnableUI(BOOL bEnable);
  275. protected:
  276. virtual void OnEditChange() {}
  277. struct RANGE_INFO
  278. {
  279. RANGE_INFO()
  280. { memset(this, 0x0, sizeof(RANGE_INFO));}
  281. UINT m_nMinVal;
  282. UINT m_nMaxVal;
  283. };
  284. CDNSTimeIntervalEdit m_edit;
  285. CDNSTimeUnitComboBox m_timeUnitCombo;
  286. RANGE_INFO m_rangeInfoArr[4]; // for sec, min, hrs, days
  287. UINT m_nRangeCount;
  288. UINT m_nMaxVal;
  289. UINT m_nMinVal;
  290. private:
  291. virtual void InitRangeInfo();
  292. void OnComboSelChange();
  293. void OnEditKillFocus();
  294. friend class CDNSTimeIntervalEdit;
  295. friend class CDNSTimeUnitComboBox;
  296. };
  297. //////////////////////////////////////////////////////////////////////////
  298. // CDNSManageControlTextHelper
  299. class CDNSManageControlTextHelper
  300. {
  301. public:
  302. CDNSManageControlTextHelper(int nStates);
  303. ~CDNSManageControlTextHelper();
  304. BOOL Init(CWnd* pParentWnd, UINT nID, UINT* pnStrArray);
  305. BOOL Init(CWnd* pParentWnd, UINT nID);
  306. void SetStateX(int nIndex);
  307. private:
  308. CWnd* m_pParentWnd;
  309. UINT m_nID;
  310. WCHAR* m_lpszText;
  311. int m_nStates;
  312. LPWSTR* m_lpszArr;
  313. };
  314. //////////////////////////////////////////////////////////////////////////
  315. // CDNSToggleTextControlHelper
  316. class CDNSToggleTextControlHelper : public CDNSManageControlTextHelper
  317. {
  318. public:
  319. CDNSToggleTextControlHelper();
  320. void SetToggleState(BOOL bFirst) { SetStateX(bFirst ? 0 : 1);}
  321. };
  322. ///////////////////////////////////////////////////////////////////////////
  323. // CDNSManageButtonTextHelper
  324. class CDNSManageButtonTextHelper
  325. {
  326. public:
  327. CDNSManageButtonTextHelper(int nStates);
  328. ~CDNSManageButtonTextHelper();
  329. BOOL Init(CWnd* pParentWnd, UINT nButtonID, UINT* nStrArray);
  330. void SetStateX(int nIndex);
  331. private:
  332. CWnd* m_pParentWnd;
  333. UINT m_nID;
  334. WCHAR* m_lpszText;
  335. int m_nStates;
  336. LPWSTR* m_lpszArr;
  337. };
  338. ///////////////////////////////////////////////////////////////////////////
  339. // CDNSButtonToggleTextHelper
  340. class CDNSButtonToggleTextHelper : public CDNSManageButtonTextHelper
  341. {
  342. public:
  343. CDNSButtonToggleTextHelper();
  344. void SetToggleState(BOOL bFirst) { SetStateX(bFirst ? 0 : 1); }
  345. };
  346. /////////////////////////////////////////////////////////////////////////////
  347. // CDlgWorkerThread
  348. class CLongOperationDialog; // fwd decl
  349. class CDlgWorkerThread : public CWorkerThread
  350. {
  351. public:
  352. CDlgWorkerThread();
  353. BOOL Start(CLongOperationDialog* pDlg);
  354. virtual int Run(); // MFC override
  355. DWORD GetError() { return m_dwErr;}
  356. protected:
  357. virtual void OnDoAction() = 0;
  358. DWORD m_dwErr;
  359. private:
  360. BOOL PostMessageToDlg();
  361. friend CLongOperationDialog;
  362. };
  363. /////////////////////////////////////////////////////////////////////////////
  364. // CLongOperationDialog dialog
  365. class CLongOperationDialog : public CDialog
  366. {
  367. // Construction
  368. public:
  369. static UINT s_nNotificationMessage;
  370. CLongOperationDialog(CDlgWorkerThread* pThreadObj, CWnd* pParentWnd, UINT nAviID = -1);
  371. virtual ~CLongOperationDialog();
  372. virtual INT_PTR DoModal()
  373. {
  374. if (m_bExecuteNoUI)
  375. {
  376. GetThreadObj()->OnDoAction();
  377. m_bAbandoned = FALSE;
  378. return IDOK;
  379. }
  380. return CDialog::DoModal();
  381. }
  382. BOOL LoadTitleString(UINT nID);
  383. CDlgWorkerThread* GetThreadObj()
  384. {
  385. ASSERT(m_pThreadObj != NULL);
  386. return m_pThreadObj;
  387. }
  388. UINT m_nAviID;
  389. CString m_szTitle;
  390. BOOL m_bAbandoned;
  391. BOOL m_bExecuteNoUI;
  392. afx_msg LONG OnNotificationMessage( WPARAM wParam, LPARAM lParam);
  393. // Implementation
  394. protected:
  395. // Generated message map functions
  396. virtual BOOL OnInitDialog();
  397. virtual void OnCancel();
  398. DECLARE_MESSAGE_MAP()
  399. private:
  400. CDlgWorkerThread* m_pThreadObj;
  401. };
  402. //////////////////////////////////////////////////////////
  403. // CNodeEnumerationThread
  404. class CNodeEnumerationThread : public CDlgWorkerThread
  405. {
  406. public:
  407. CNodeEnumerationThread(CComponentDataObject* pComponentDataObject,
  408. CMTContainerNode* pNode);
  409. ~CNodeEnumerationThread();
  410. protected:
  411. virtual void OnDoAction();
  412. void OnAbandon();
  413. private:
  414. CComponentDataObject* m_pComponentDataObject;
  415. CNotificationSinkEvent* m_pSink;
  416. CMTContainerNode* m_pNode;
  417. };
  418. //////////////////////////////////////////////////////////
  419. // CArrayCheckListBox
  420. class CArrayCheckListBox : public CCheckListBox
  421. {
  422. public:
  423. CArrayCheckListBox(UINT nArrSize, DWORD* dwMaskArr = NULL)
  424. { m_nArrSize = nArrSize; m_dwMaskArr = dwMaskArr; }
  425. BOOL Initialize(UINT nCtrlID, UINT nStringID, CWnd* pParentWnd);
  426. void SetValue(DWORD dw);
  427. DWORD GetValue();
  428. void SetArrValue(DWORD* dwArr, UINT nArrSize);
  429. void GetArrValue(DWORD* dwArr, UINT nArrSize);
  430. private:
  431. DWORD* m_dwMaskArr;
  432. UINT m_nArrSize;
  433. };
  434. ////////////////////////////////////////////////////////////////////////////
  435. // CDNS_AGING_TimeIntervalEditGroup
  436. class CDNSZone_AgingDialog; // Foward declaration
  437. class CDNSServer_AdvancedPropertyPage; // Fwd declaration
  438. class CDNS_AGING_TimeIntervalEditGroup : public CDNSTimeIntervalEditGroup
  439. {
  440. public:
  441. CDNS_AGING_TimeIntervalEditGroup(UINT nMinVal = 0 , UINT nMaxVal = (UINT)0x7fffffff)
  442. : CDNSTimeIntervalEditGroup(nMinVal, nMaxVal)
  443. {
  444. m_pPage = NULL;
  445. }
  446. virtual void OnEditChange();
  447. virtual void SetVal(UINT nVal);
  448. virtual UINT GetVal();
  449. virtual void InitRangeInfo();
  450. protected:
  451. CDNSZone_AgingDialog* m_pPage;
  452. friend class CDNSZone_AgingDialog;
  453. };
  454. class CDNS_SERVER_AGING_TimeIntervalEditGroup : public CDNS_AGING_TimeIntervalEditGroup
  455. {
  456. public:
  457. CDNS_SERVER_AGING_TimeIntervalEditGroup(UINT nMinVal = 0 , UINT nMaxVal = (UINT)0x7fffffff)
  458. : CDNS_AGING_TimeIntervalEditGroup(nMinVal, nMaxVal)
  459. {
  460. m_pPage2 = NULL;
  461. }
  462. virtual void OnEditChange();
  463. protected:
  464. CDNSServer_AdvancedPropertyPage* m_pPage2;
  465. friend class CDNSServer_AdvancedPropertyPage;
  466. };
  467. ////////////////////////////////////////////////////////////////////////////
  468. // CDNSZone_AgingDialog
  469. class CDNSZone_AgingDialog : public CHelpDialog
  470. {
  471. public:
  472. CDNSZone_AgingDialog(CPropertyPageHolderBase* pHolder, UINT nID, CComponentDataObject* pComponentData);
  473. // IN/OUT
  474. DWORD m_dwRefreshInterval;
  475. DWORD m_dwNoRefreshInterval;
  476. DWORD m_dwScavengingStart;
  477. DWORD m_fScavengingEnabled;
  478. BOOL m_bAdvancedView;
  479. BOOL m_bScavengeDirty;
  480. BOOL m_bNoRefreshDirty;
  481. BOOL m_bRefreshDirty;
  482. BOOL m_bApplyAll;
  483. BOOL m_bADApplyAll;
  484. BOOL m_bStandardApplyAll;
  485. DWORD m_dwDefaultRefreshInterval;
  486. DWORD m_dwDefaultNoRefreshInterval;
  487. BOOL m_bDefaultScavengingState;
  488. virtual void SetDirty();
  489. BOOL IsDirty() { return m_bDirty; }
  490. CComponentDataObject* GetComponentData() { return m_pComponentData; }
  491. protected:
  492. virtual BOOL OnInitDialog();
  493. virtual void OnOK();
  494. virtual void OnCancel();
  495. afx_msg void OnCheckScavenge();
  496. afx_msg void OnEditNoRefresh();
  497. afx_msg void OnEditRefresh();
  498. void GetTimeStampString(CString& cstrDate);
  499. void SetUIData();
  500. DECLARE_MESSAGE_MAP()
  501. CPropertyPageHolderBase* m_pHolder;
  502. CDNS_AGING_TimeIntervalEditGroup m_refreshIntervalEditGroup;
  503. CDNS_AGING_TimeIntervalEditGroup m_norefreshIntervalEditGroup;
  504. CComponentDataObject* m_pComponentData;
  505. BOOL m_bDirty;
  506. };
  507. ////////////////////////////////////////////////////////////////////////////////////
  508. // CDNSServer_AgingConfirm
  509. class CDNSServer_AgingConfirm : public CHelpDialog
  510. {
  511. public:
  512. CDNSServer_AgingConfirm(CDNSZone_AgingDialog* pAgingDialog)
  513. : CHelpDialog(IDD_SERVER_AGING_CONFIRMATION, pAgingDialog->GetComponentData())
  514. {
  515. ASSERT(pAgingDialog != NULL);
  516. m_pAgingDialog = pAgingDialog;
  517. }
  518. protected:
  519. virtual BOOL OnInitDialog();
  520. virtual void OnOK();
  521. void SetAgingUpdateValues();
  522. private:
  523. CDNSZone_AgingDialog* m_pAgingDialog;
  524. };
  525. /////////////////////////////////////////////////////////////////////////////////////
  526. typedef struct _COMBOBOX_TABLE_ENTRY
  527. {
  528. UINT nComboStringID;
  529. DWORD dwComboData;
  530. } COMBOBOX_TABLE_ENTRY, *PCOMBOBOX_TABLE_ENTRY;
  531. BOOL LoadComboBoxFromTable(CComboBox* pComboBox, PCOMBOBOX_TABLE_ENTRY pTable);
  532. BOOL SetComboSelByData(CComboBox* pComboBox, DWORD dwData);
  533. #endif // __UIUTIL_H