autopopup.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #include <precomp.h>
  2. #include "autopopup.h"
  3. static PtrListQuickSorted<AutoPopupEntry, AutoPopupEntrySort> entries;
  4. static int nid=0;
  5. int AutoPopup::registerGuid(int skinpartid, GUID g, const wchar_t *desc, const wchar_t *prefered_container, int required)
  6. {
  7. if (desc == NULL || !*desc) desc = L"[????]";
  8. AutoPopupEntry *ape = new AutoPopupEntry(skinpartid, g, NULL, desc, prefered_container, required);
  9. entries.addItem(ape);
  10. return ape->getNid();
  11. }
  12. int AutoPopup::registerGroupId(int skinpartid, const wchar_t *groupid, const wchar_t *desc, const wchar_t *prefered_container, int required) {
  13. if (desc == NULL || !*desc) desc = L"[????]";
  14. AutoPopupEntry *ape = new AutoPopupEntry(skinpartid, INVALID_GUID, groupid, desc, prefered_container, required);
  15. entries.addItem(ape);
  16. return ape->getNid();
  17. }
  18. int AutoPopup::getNumItems() { return entries.getNumItems(); }
  19. AutoPopupEntry *AutoPopup::enumItem(int n) { return entries.enumItem(n); }
  20. int AutoPopup::getNumGroups() {
  21. int n = 0;
  22. foreach(entries)
  23. AutoPopupEntry *e = entries.getfor();
  24. if (e->getGroupId() != NULL && e->getGuid() == INVALID_GUID) n++;
  25. endfor;
  26. return n;
  27. }
  28. int AutoPopup::getNumGuids() {
  29. int n = 0;
  30. foreach(entries)
  31. AutoPopupEntry *e = entries.getfor();
  32. if (e->getGroupId() == NULL && e->getGuid() != INVALID_GUID) n++;
  33. endfor;
  34. return n;
  35. }
  36. const wchar_t *AutoPopup::enumGroup(int n) {
  37. int c = 0;
  38. foreach(entries)
  39. AutoPopupEntry *e = entries.getfor();
  40. if (e->getGroupId() != NULL && e->getGuid() == INVALID_GUID) {
  41. if (c == n) return e->getGroupId();
  42. c++;
  43. }
  44. endfor;
  45. return NULL;
  46. }
  47. GUID AutoPopup::enumGuid(int n) {
  48. int c = 0;
  49. foreach(entries)
  50. AutoPopupEntry *e = entries.getfor();
  51. if (e->getGroupId() == NULL && e->getGuid() != INVALID_GUID) {
  52. if (c == n) return e->getGuid();
  53. c++;
  54. }
  55. endfor;
  56. return INVALID_GUID;
  57. }
  58. const wchar_t *AutoPopup::enumGroupDescription(int n) {
  59. int c = 0;
  60. foreach(entries)
  61. AutoPopupEntry *e = entries.getfor();
  62. if (e->getGroupId() != NULL && e->getGuid() == INVALID_GUID) {
  63. if (c == n) return e->getDescription();
  64. c++;
  65. }
  66. endfor;
  67. return NULL;
  68. }
  69. const wchar_t *AutoPopup::enumGuidDescription(int n) {
  70. int c = 0;
  71. foreach(entries)
  72. AutoPopupEntry *e = entries.getfor();
  73. if (e->getGroupId() == NULL && e->getGuid() != INVALID_GUID) {
  74. if (c == n) return e->getDescription();
  75. c++;
  76. }
  77. endfor;
  78. return NULL;
  79. }
  80. AutoPopupEntry *AutoPopup::getByDesc(const wchar_t *desc) {
  81. foreach(entries)
  82. if (!WCSICMP(desc, entries.getfor()->getDescription()))
  83. return entries.getfor();
  84. endfor;
  85. return NULL;
  86. }
  87. void AutoPopup::reset() { entries.deleteAll(); nid = 0; }
  88. const wchar_t *AutoPopup::getDefaultContainerParams(const wchar_t *groupid, GUID g, int *flag) {
  89. if (groupid == NULL) { // guid
  90. for (int i=entries.getNumItems()-1;i>=0;i--) {
  91. if (entries.enumItem(i)->getGuid() == g) {
  92. if (flag != NULL) *flag = entries.enumItem(i)->getContainerHow();
  93. return entries.enumItem(i)->getPreferedContainer();
  94. }
  95. }
  96. } else { // groupid
  97. for (int i=entries.getNumItems()-1;i>=0;i--)
  98. {
  99. if (WCSCASEEQLSAFE(entries.enumItem(i)->getGroupId(), groupid))
  100. {
  101. if (flag != NULL) *flag = entries.enumItem(i)->getContainerHow();
  102. return entries.enumItem(i)->getPreferedContainer();
  103. }
  104. }
  105. }
  106. return NULL;
  107. }
  108. void AutoPopup::unregister(int id) {
  109. for (int i=0;i<entries.getNumItems();i++) {
  110. AutoPopupEntry *ape = entries.enumItem(i);
  111. if (ape->getNid() == id) {
  112. delete ape;
  113. entries.removeByPos(i);
  114. i--;
  115. continue;
  116. }
  117. }
  118. }
  119. void AutoPopup::removeSkinPart(int id) {
  120. for (int i=0;i<entries.getNumItems();i++) {
  121. AutoPopupEntry *ape = entries.enumItem(i);
  122. if (ape->getSkinpart() == id) {
  123. delete ape;
  124. entries.removeByPos(i);
  125. i--;
  126. }
  127. }
  128. }
  129. int AutoPopup::allocNid() { return nid++; }
  130. void AutoPopup::removeAllAddons() {
  131. for (int i=0;i<entries.getNumItems();i++) {
  132. AutoPopupEntry *ape = entries.enumItem(i);
  133. if (ape->getSkinpart() != SKINPARTID_NONE) {
  134. delete ape;
  135. entries.removeByPos(i);
  136. i--;
  137. }
  138. }
  139. }