setupGroupList.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #include "./setupGroupList.h"
  2. #include "../api__ml_online.h"
  3. #include <strsafe.h>
  4. SetupGroupList::SetupGroupList()
  5. : ref(1)
  6. {
  7. }
  8. SetupGroupList::~SetupGroupList()
  9. {
  10. size_t index = list.size();
  11. while(index--)
  12. {
  13. list[index]->Release();
  14. }
  15. }
  16. SetupGroupList *SetupGroupList::CreateInstance()
  17. {
  18. return new SetupGroupList();
  19. }
  20. ULONG SetupGroupList::AddRef()
  21. {
  22. return InterlockedIncrement((LONG*)&ref);
  23. }
  24. ULONG SetupGroupList::Release()
  25. {
  26. if (0 == ref)
  27. return ref;
  28. LONG r = InterlockedDecrement((LONG*)&ref);
  29. if (0 == r)
  30. delete(this);
  31. return r;
  32. }
  33. BOOL SetupGroupList::AddGroup(SetupGroup *group)
  34. {
  35. if (NULL == group) return FALSE;
  36. list.push_back(group);
  37. group->AddRef();
  38. return TRUE;
  39. }
  40. size_t SetupGroupList::GetGroupCount()
  41. {
  42. return list.size();
  43. }
  44. BOOL SetupGroupList::IsModified()
  45. {
  46. size_t index = list.size();
  47. while(index--)
  48. {
  49. if (list[index]->IsModified())
  50. return TRUE;
  51. }
  52. return FALSE;
  53. }
  54. BOOL SetupGroupList::FindGroupIndex(SetupGroup *group, size_t *groupIndex)
  55. {
  56. if (NULL == group) return FALSE;
  57. size_t index = list.size();
  58. while(index--)
  59. {
  60. if (list[index] == group)
  61. {
  62. if (NULL != groupIndex)
  63. *groupIndex = index;
  64. return TRUE;
  65. }
  66. }
  67. return FALSE;
  68. }
  69. HRESULT SetupGroupList::FindGroupById(UINT groupId, SetupGroup **group)
  70. {
  71. if (NULL == group) return E_POINTER;
  72. size_t index = list.size();
  73. while(index--)
  74. {
  75. if (list[index]->GetId() == groupId)
  76. {
  77. *group = list[index];
  78. (*group)->AddRef();
  79. return S_OK;
  80. }
  81. }
  82. return S_FALSE;
  83. }
  84. size_t SetupGroupList::GetListboxCount()
  85. {
  86. size_t recordCount = list.size();
  87. size_t index = recordCount;
  88. while(index--)
  89. {
  90. recordCount += list[index]->GetListboxCount();
  91. }
  92. return recordCount;
  93. }
  94. HRESULT SetupGroupList::Save(SetupLog *log)
  95. {
  96. HRESULT hr(S_OK);
  97. size_t index = list.size();
  98. while(index--)
  99. {
  100. if (FAILED(list[index]->Save(log)))
  101. hr = E_FAIL;
  102. }
  103. return hr;
  104. }
  105. HRESULT SetupGroupList::FindListboxItem(size_t listboxId, SetupListboxItem **listboxItem)
  106. {
  107. if (NULL == listboxItem) return E_POINTER;
  108. size_t index = 0;
  109. size_t groupCount = list.size();
  110. SetupGroup *group;
  111. for (size_t i = 0; i < groupCount; i++)
  112. {
  113. group = list[i];
  114. if (index == listboxId)
  115. {
  116. *listboxItem = (SetupListboxItem*)group;
  117. return S_OK;
  118. }
  119. index++;
  120. size_t itemCount;
  121. if (0 != (itemCount = group->GetListboxCount()))
  122. {
  123. if (listboxId < (index + itemCount))
  124. {
  125. size_t itemIndex = (listboxId - index);
  126. *listboxItem = group->GetListboxItem(itemIndex);
  127. return S_OK;
  128. }
  129. index += itemCount;
  130. }
  131. }
  132. return E_NOTIMPL;
  133. }
  134. INT SetupGroupList::GetListboxItem(SetupListboxItem *item)
  135. {
  136. if (NULL == item) return LB_ERR;
  137. size_t index = 0;
  138. size_t groupCount = list.size();
  139. SetupGroup *group;
  140. SetupListboxItem *groupItem;
  141. for (size_t i = 0; i < groupCount; i++)
  142. {
  143. group = list[i];
  144. if (item == group)
  145. return (INT)index;
  146. index++;
  147. size_t itemCount = group->GetListboxCount();
  148. for (size_t j = 0; j < itemCount; j++)
  149. {
  150. groupItem = group->GetListboxItem(j);
  151. if (groupItem == item)
  152. return (INT)index;
  153. index++;
  154. }
  155. }
  156. return LB_ERR;
  157. }
  158. void SetupGroupList::SetPageWnd(HWND hPage)
  159. {
  160. size_t index = list.size();
  161. while(index--)
  162. {
  163. list[index]->SetPageWnd(hPage);
  164. }
  165. }