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.

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