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.

132 lines
5.2 KiB

  1. #ifndef _INC_DSKQUOTA_XBYTES_H
  2. #define _INC_DSKQUOTA_XBYTES_H
  3. ///////////////////////////////////////////////////////////////////////////////
  4. /* File: xbytes.h
  5. Description: This module implements a class t hat coordinates the operation
  6. between the edit control and combo box used for entering byte values.
  7. The name "XBytes" is used because the control can represent
  8. KBytes, MBytes, GBytes etc.
  9. The cooperation between edit control and combo control is required
  10. so that the user can enter a byte value in the edit control then
  11. indicate it's order (KB, MB, GB...) using a selection from the combo box.
  12. A simple external interface is provided to initially set the
  13. object's byte value then retrieve the byte value when needed. The
  14. object's client is also required to call two member functions when
  15. the parent dialog receives an EN_UPDATE notification and a CBN_SELCHANGE
  16. message. The XBytes object handles all of the value scaling
  17. internally.
  18. Revision History:
  19. Date Description Programmer
  20. -------- --------------------------------------------------- ----------
  21. 08/30/96 Initial creation. BrianAu
  22. 10/15/96 Added m_MaxBytes member. BrianAu
  23. 10/22/96 Added ValueInRange() member. BrianAu
  24. 05/29/98 Removed ValueInRange() and m_MaxBytes members. BrianAu
  25. 11/01/01 Copied from BrianAu for use in CYS JeffJon
  26. */
  27. ///////////////////////////////////////////////////////////////////////////////
  28. const INT MAX_DECIMAL_SEP = 10;
  29. const INT MAX_NOLIMIT_LEN = 80; // This should be plenty for localization.
  30. #define MAX_ORDER e_Exa
  31. #define VALID_ORDER(ord) ((ord) >= e_Byte && (ord) <= MAX_ORDER)
  32. class XBytes
  33. {
  34. private:
  35. INT64 m_ValueBytes; // Byte value.
  36. HWND m_hDlg; // Parent dlg.
  37. DWORD m_idCtlEdit; // Edit control.
  38. DWORD m_idCtlCombo; // Combo control.
  39. static TCHAR m_szNoLimit[MAX_NOLIMIT_LEN];
  40. VOID CommonInit(VOID);
  41. inline BOOL IsCharNumeric(TCHAR ch)
  42. { return IsCharAlphaNumeric(ch) && !IsCharAlpha(ch); }
  43. //BOOL StrToInt(LPCTSTR pszValue, INT64 *pIntValue);
  44. inline INT_PTR SendToEditCtl(UINT message, WPARAM wParam, LPARAM lParam)
  45. { return SendMessage(GetDlgItem(m_hDlg, m_idCtlEdit), message, wParam, lParam); }
  46. inline INT_PTR SendToCombo(UINT message, WPARAM wParam, LPARAM lParam)
  47. { return SendMessage(GetDlgItem(m_hDlg, m_idCtlCombo), message, wParam, lParam); }
  48. inline INT_PTR GetOrderFromCombo(VOID)
  49. { return SendToCombo(CB_GETCURSEL, 0, 0) + 1; }
  50. inline INT_PTR SetOrderInCombo(INT iOrder)
  51. { return SendToCombo(CB_SETCURSEL, iOrder-1, 0); }
  52. VOID LoadComboItems(INT64 MaxBytes);
  53. VOID SetBestDisplay(VOID);
  54. BOOL Store(INT64 Value, INT xbOrder);
  55. BOOL Store(LPCTSTR pszValue, INT xbOrder);
  56. INT64 Fetch(INT64 *pDecimal, INT xbOrder); // Fetch in requested order.
  57. DWORD Fetch(DWORD *pDecimal, INT *pxbOrder); // Fetch in "best" order.
  58. bool UndoLastEdit(void);
  59. static VOID LoadStaticStrings(void);
  60. static VOID FormatForDisplay(LPTSTR pszDest,
  61. UINT cchDest,
  62. DWORD dwWholePart,
  63. DWORD dwFracPart);
  64. public:
  65. VOID Enable(BOOL bEnable);
  66. //
  67. // With the exception of e_Byte, these must match the order
  68. // of the IDS_ORDERKB, IDS_ORDERMB... string resource IDs.
  69. // There is no IDS_ORDERBYTE string resource.
  70. //
  71. enum {e_Byte, e_Kilo, e_Mega, e_Giga, e_Tera, e_Peta, e_Exa};
  72. XBytes(VOID);
  73. XBytes(HWND hDlg, DWORD idCtlEdit, DWORD idCtlCombo, INT64 CurrentBytes);
  74. void
  75. Initialize(
  76. HWND hDlg,
  77. DWORD idCtlEdit,
  78. DWORD idCtlCombo,
  79. INT64 CurrentBytes);
  80. static double ConvertFromBytes(INT64 ValueBytes, INT xbOrder);
  81. static INT64 BytesToParts(INT64 ValueBytes, INT64 *pDecimal, INT xbOrder);
  82. static DWORD BytesToParts(INT64 ValueBytes, LPDWORD pDecimal, INT *pxbOrder);
  83. static VOID FormatByteCountForDisplay(INT64 Bytes, LPTSTR pszDest, UINT cchDest);
  84. static VOID FormatByteCountForDisplay(INT64 Bytes, LPTSTR pszDest, UINT cchDest, INT *pOrder);
  85. static VOID FormatByteCountForDisplay(INT64 Bytes, LPTSTR pszDest, UINT cchDest, INT Order);
  86. INT64 GetBytes(VOID)
  87. { return Fetch(NULL, e_Byte); }
  88. VOID SetBytes(INT64 Value);
  89. //
  90. // EN_xxxx handlers. Client must call this on EN_UPDATE.
  91. //
  92. BOOL OnEditNotifyUpdate();
  93. BOOL OnEditKillFocus();
  94. //
  95. // CBN_xxxx handlers. Client must call this on CBN_SELCHANGE.
  96. //
  97. BOOL OnComboNotifySelChange();
  98. BOOL IsEnabled(VOID);
  99. };
  100. #endif // _INC_DSKQUOTA_XBYTES_H