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.

123 lines
5.0 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 that 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. */
  26. ///////////////////////////////////////////////////////////////////////////////
  27. const INT MAX_DECIMAL_SEP = 10;
  28. const INT MAX_NOLIMIT_LEN = 80; // This should be plenty for localization.
  29. #define MAX_ORDER e_Exa
  30. #define VALID_ORDER(ord) ((ord) >= e_Byte && (ord) <= MAX_ORDER)
  31. class XBytes
  32. {
  33. private:
  34. INT64 m_ValueBytes; // Byte value.
  35. HWND m_hDlg; // Parent dlg.
  36. DWORD m_idCtlEdit; // Edit control.
  37. DWORD m_idCtlCombo; // Combo control.
  38. static TCHAR m_szNoLimit[MAX_NOLIMIT_LEN];
  39. VOID CommonInit(VOID);
  40. INLINE BOOL IsCharNumeric(TCHAR ch)
  41. { return IsCharAlphaNumeric(ch) && !IsCharAlpha(ch); }
  42. BOOL StrToInt(LPCTSTR pszValue, INT64 *pIntValue);
  43. INLINE INT_PTR SendToEditCtl(UINT message, WPARAM wParam, LPARAM lParam)
  44. { return SendMessage(GetDlgItem(m_hDlg, m_idCtlEdit), message, wParam, lParam); }
  45. INLINE INT_PTR SendToCombo(UINT message, WPARAM wParam, LPARAM lParam)
  46. { return SendMessage(GetDlgItem(m_hDlg, m_idCtlCombo), message, wParam, lParam); }
  47. INLINE INT_PTR GetOrderFromCombo(VOID)
  48. { return SendToCombo(CB_GETCURSEL, 0, 0) + 1; }
  49. INLINE INT_PTR SetOrderInCombo(INT iOrder)
  50. { return SendToCombo(CB_SETCURSEL, iOrder-1, 0); }
  51. VOID LoadComboItems(INT64 MaxBytes);
  52. VOID SetBestDisplay(VOID);
  53. BOOL Store(INT64 Value, INT xbOrder);
  54. BOOL Store(LPCTSTR pszValue, INT xbOrder);
  55. INT64 Fetch(INT64 *pDecimal, INT xbOrder); // Fetch in requested order.
  56. DWORD Fetch(DWORD *pDecimal, INT *pxbOrder); // Fetch in "best" order.
  57. bool UndoLastEdit(void);
  58. static VOID LoadStaticStrings(void);
  59. static VOID FormatForDisplay(LPTSTR pszDest,
  60. UINT cchDest,
  61. DWORD dwWholePart,
  62. DWORD dwFracPart);
  63. VOID Enable(BOOL bEnable);
  64. public:
  65. //
  66. // With the exception of e_Byte, these must match the order
  67. // of the IDS_ORDERKB, IDS_ORDERMB... string resource IDs.
  68. // There is no IDS_ORDERBYTE string resource.
  69. //
  70. enum {e_Byte, e_Kilo, e_Mega, e_Giga, e_Tera, e_Peta, e_Exa};
  71. XBytes(VOID);
  72. XBytes(HWND hDlg, DWORD idCtlEdit, DWORD idCtlCombo, INT64 CurrentBytes);
  73. static double ConvertFromBytes(INT64 ValueBytes, INT xbOrder);
  74. static INT64 BytesToParts(INT64 ValueBytes, INT64 *pDecimal, INT xbOrder);
  75. static DWORD BytesToParts(INT64 ValueBytes, LPDWORD pDecimal, INT *pxbOrder);
  76. static VOID FormatByteCountForDisplay(INT64 Bytes, LPTSTR pszDest, UINT cchDest);
  77. static VOID FormatByteCountForDisplay(INT64 Bytes, LPTSTR pszDest, UINT cchDest, INT *pOrder);
  78. static VOID FormatByteCountForDisplay(INT64 Bytes, LPTSTR pszDest, UINT cchDest, INT Order);
  79. INT64 GetBytes(VOID)
  80. { return Fetch(NULL, e_Byte); }
  81. VOID SetBytes(INT64 Value);
  82. //
  83. // EN_xxxx handlers. Client must call this on EN_UPDATE.
  84. //
  85. BOOL OnEditNotifyUpdate(LPARAM lParam);
  86. BOOL OnEditKillFocus(LPARAM lParam);
  87. //
  88. // CBN_xxxx handlers. Client must call this on CBN_SELCHANGE.
  89. //
  90. BOOL OnComboNotifySelChange(LPARAM lParam);
  91. BOOL IsEnabled(VOID);
  92. };
  93. #endif // _INC_DSKQUOTA_XBYTES_H