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.

179 lines
4.8 KiB

  1. // rowitem.h - CRowItem header file
  2. #ifndef _ROWITEM_H_
  3. #define _ROWITEM_H_
  4. #define DEFAULT_ATTR_SIZE 32
  5. #define EXTENSION_SIZE 256
  6. // First two attributes are fixed followed by user defined attributes
  7. enum ROWITEM_ATTR_INDEX
  8. {
  9. ROWITEM_PATH_INDEX = -1, // Path is not an indexed attribute, but is stored like one
  10. ROWITEM_NAME_INDEX = 0, // Object name (usually cn, but depends on class)
  11. ROWITEM_CLASS_INDEX = 1, // Class name (display name, not LDAP name)
  12. ROWITEM_USER_INDEX = 2 // First user selected attribute
  13. };
  14. #define INTERNAL_ATTR_COUNT 1 // Number of internal attributes (ones with negative indicies)
  15. class CRowItem
  16. {
  17. typedef struct
  18. {
  19. LPARAM lOwnerParam; // Row item owner parameter
  20. UINT iIcon; // virtual index of the icon
  21. bool bDisabled; // disabled flag for icon state
  22. int bcSize; // size of buffer
  23. int bcFree; // size of free space
  24. int nRefCnt; // ref count for sharing buffer among CRowItems
  25. int nAttrCnt; // number of atributes
  26. int aiOffset[1]; // attribute offset array. NOTE: this MUST be the last element
  27. } BufferHdr;
  28. public:
  29. // constructor/destructor
  30. CRowItem() : m_pBuff(NULL) {}
  31. CRowItem(int cAttributes);
  32. // Copy constructor
  33. // NOTE: unlike most classes that share a ref-counted resource, this class does not
  34. // make a private copy when there is a change to the resoruce. All instances
  35. // sharing the copy see the same change.
  36. CRowItem(const CRowItem& rRowItem)
  37. {
  38. ASSERT(rRowItem.m_pBuff != NULL);
  39. m_pBuff = rRowItem.m_pBuff;
  40. if( m_pBuff )
  41. {
  42. m_pBuff->nRefCnt++;
  43. }
  44. }
  45. CRowItem& operator= (const CRowItem& rRowItem)
  46. {
  47. if (m_pBuff == rRowItem.m_pBuff)
  48. return (*this);
  49. ASSERT(rRowItem.m_pBuff != NULL);
  50. if (m_pBuff != NULL && --(m_pBuff->nRefCnt) == 0)
  51. free(m_pBuff);
  52. m_pBuff = rRowItem.m_pBuff;
  53. if( m_pBuff )
  54. {
  55. m_pBuff->nRefCnt++;
  56. }
  57. return (*this);
  58. }
  59. virtual ~CRowItem()
  60. {
  61. if (m_pBuff != NULL && --(m_pBuff->nRefCnt) == 0)
  62. free(m_pBuff);
  63. }
  64. // public methods
  65. HRESULT SetAttribute(int iAttr, LPCWSTR pszAttr)
  66. {
  67. ASSERT(iAttr >= 0 && iAttr < m_pBuff->nAttrCnt);
  68. return SetAttributePriv(iAttr, pszAttr);
  69. }
  70. LPCWSTR operator[](int iAttr)
  71. {
  72. ASSERT(m_pBuff != NULL);
  73. if( !m_pBuff ) return L"";
  74. if( iAttr >= m_pBuff->nAttrCnt || iAttr < 0 )
  75. return L"";
  76. return GetAttributePriv(iAttr);
  77. }
  78. int size() { return m_pBuff ? m_pBuff->nAttrCnt : 0; }
  79. HRESULT SetObjPath(LPCWSTR pszPath) { return SetAttributePriv(ROWITEM_PATH_INDEX, pszPath); }
  80. LPCWSTR GetObjPath() { ASSERT( m_pBuff ); return GetAttributePriv(ROWITEM_PATH_INDEX); }
  81. void SetOwnerParam(LPARAM lParam)
  82. {
  83. ASSERT( m_pBuff );
  84. if( !m_pBuff ) return;
  85. m_pBuff->lOwnerParam = lParam;
  86. }
  87. LPARAM GetOwnerParam() { ASSERT( m_pBuff ); return m_pBuff ? m_pBuff->lOwnerParam : 0; }
  88. void SetIconIndex(UINT index)
  89. {
  90. ASSERT( m_pBuff );
  91. if( !m_pBuff ) return;
  92. m_pBuff->iIcon = index;
  93. }
  94. UINT GetIconIndex() const {ASSERT( m_pBuff ); return m_pBuff ? m_pBuff->iIcon : 0; }
  95. void SetDisabled(bool flag)
  96. {
  97. ASSERT( m_pBuff );
  98. if( !m_pBuff ) return;
  99. m_pBuff->bDisabled = flag;
  100. }
  101. bool Disabled() const { ASSERT( m_pBuff ); return m_pBuff ? m_pBuff->bDisabled : true; }
  102. protected:
  103. HRESULT SetAttributePriv(int iAttr, LPCWSTR pszAttr);
  104. LPCWSTR GetAttributePriv(int iAttr)
  105. {
  106. iAttr += INTERNAL_ATTR_COUNT;
  107. if( !m_pBuff || (m_pBuff->aiOffset[iAttr] == -1) )
  108. {
  109. return L"";
  110. }
  111. else
  112. {
  113. return reinterpret_cast<LPCWSTR>(reinterpret_cast<BYTE*>(m_pBuff) + m_pBuff->aiOffset[iAttr]);
  114. }
  115. }
  116. // member variables
  117. BufferHdr *m_pBuff;
  118. };
  119. typedef std::vector<CRowItem> RowItemVector;
  120. class CRowCompare
  121. {
  122. public:
  123. CRowCompare(int iCol, bool bDescend): m_iCol(iCol), m_bDescend(bDescend) {}
  124. int operator()(CRowItem& Item1, CRowItem& Item2) const
  125. {
  126. int iRet = CompareString(LOCALE_USER_DEFAULT,
  127. NORM_IGNORECASE|NORM_IGNOREKANATYPE|NORM_IGNOREWIDTH,
  128. Item1[m_iCol], -1, Item2[m_iCol], -1);
  129. return m_bDescend ? (iRet == CSTR_GREATER_THAN) : (iRet == CSTR_LESS_THAN);
  130. }
  131. private:
  132. int m_iCol;
  133. bool m_bDescend;
  134. };
  135. #endif // _ROWITEM_H_