guitree.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #ifndef __GUITREE_H
  2. #define __GUITREE_H
  3. #include <bfc/string/bfcstring.h>
  4. #include <bfc/ptrlist.h>
  5. #include <bfc/nsguid.h>
  6. #include <api/timer/timerclient.h>
  7. #include <api/xml/xmlreader.h>
  8. #include <api/xml/xmlparamsi.h>
  9. #include <api/skin/skinitem.h>
  10. #include <bfc/string/StringW.h>
  11. #define CB_GUITREE 0x987
  12. #define INVALIDATEGRP 1
  13. #define INVALIDATETYPE 2
  14. class GuiTreeCB {
  15. public:
  16. int cmd;
  17. StringW *ptr;
  18. };
  19. class GuiTreeItem : public SkinItemI
  20. {
  21. public:
  22. GuiTreeItem(int type, const wchar_t *name, ifc_xmlreaderparams *p, int scriptid, const wchar_t *rootpath, GUID g, const wchar_t *windowtype, const wchar_t *xuitag);
  23. virtual ~GuiTreeItem();
  24. virtual int getType();
  25. virtual const wchar_t *getName();
  26. virtual int getSkinPartId() { return getScriptId(); }
  27. virtual int getScriptId();
  28. virtual ifc_xmlreaderparams *getParams();
  29. virtual const wchar_t *getXmlRootPath();
  30. virtual void setIdx(int i) { idx = i; }
  31. virtual int getIdx() { return idx; }
  32. virtual int getSecCount() { return seccount; }
  33. virtual void setGuid(GUID g) { guid = g; }
  34. virtual GUID getGuid() { return guid; }
  35. virtual const wchar_t *getWindowType() { return wndtype; }
  36. virtual const wchar_t *getXuiTag() { return tag; }
  37. virtual void setXuiTag(const wchar_t *xuitag) { tag = xuitag; }
  38. virtual SkinItem *getAncestor();
  39. private:
  40. XmlReaderParamsI params;
  41. int object_type;
  42. StringW object_name;
  43. int scriptId;
  44. StringW rootpath;
  45. int idx;
  46. int seccount;
  47. GUID guid;
  48. StringW wndtype;
  49. StringW tag;
  50. static int incrementor;
  51. };
  52. class SortGuiTreeItem
  53. {
  54. public:
  55. static int compareItem(GuiTreeItem *p1, GuiTreeItem *p2) {
  56. int r = WCSICMP(p1->getParams()->getItemValue(L"id"), p2->getParams()->getItemValue(L"id"));
  57. if (!r) {
  58. if (p1->getScriptId() < p2->getScriptId()) return -1;
  59. if (p1->getScriptId() > p2->getScriptId()) return 1;
  60. if (p1->getSecCount() < p2->getSecCount()) return -1;
  61. if (p1->getSecCount() > p2->getSecCount()) return 1;
  62. return 0;
  63. }
  64. return r;
  65. }
  66. static int compareAttrib(const wchar_t *attrib, GuiTreeItem *item) {
  67. return WCSICMP(attrib, item->getParams()->getItemValue(L"id"));
  68. }
  69. };
  70. class SortGuiTreeItemByXuiTag {
  71. public:
  72. static int compareItem(GuiTreeItem *p1, GuiTreeItem *p2) {
  73. int r = WCSICMP(p1->getParams()->getItemValue(L"xuitag"), p2->getParams()->getItemValue(L"xuitag"));
  74. if (!r) {
  75. if (p1->getScriptId() < p2->getScriptId()) return -1;
  76. if (p1->getScriptId() > p2->getScriptId()) return 1;
  77. if (p1->getSecCount() < p2->getSecCount()) return -1;
  78. if (p1->getSecCount() > p2->getSecCount()) return 1;
  79. return 0;
  80. }
  81. return r;
  82. }
  83. static int compareAttrib(const wchar_t *attrib, GuiTreeItem *item) {
  84. return WCSICMP(attrib, item->getParams()->getItemValue(L"xuitag"));
  85. }
  86. };
  87. class SortGuiTreeItemByGuid
  88. {
  89. public:
  90. static int compareItem(GuiTreeItem *p1, GuiTreeItem *p2) {
  91. GUID g1 = p1->getGuid();
  92. GUID g2 = p2->getGuid();
  93. if (g1 == g2) {
  94. if (p1->getScriptId() < p2->getScriptId()) return -1;
  95. if (p1->getScriptId() > p2->getScriptId()) return 1;
  96. if (p1->getSecCount() < p2->getSecCount()) return -1;
  97. if (p1->getSecCount() > p2->getSecCount()) return 1;
  98. return 0;
  99. }
  100. return nsGUID::compare(g1, g2) < 0 ? -1 : 1;
  101. }
  102. static int compareAttrib(const wchar_t *attrib, GuiTreeItem *item) {
  103. const GUID *g = reinterpret_cast<const GUID *>(attrib);
  104. ASSERT(g);
  105. GUID g1 = *g;
  106. GUID g2 = item->getGuid();
  107. if (g1 == g2) return 0;
  108. return nsGUID::compare(g1, g2) < 0 ? -1 : 1;
  109. }
  110. };
  111. #define GUITREE_PARENT TimerClientDI
  112. class GuiTree : public GUITREE_PARENT {
  113. public:
  114. GuiTree();
  115. virtual ~GuiTree();
  116. void addItem(int object_type, const wchar_t *object_name, ifc_xmlreaderparams *params, int scriptId, const wchar_t *rootpath);
  117. SkinItem *getGroupDef(const wchar_t *id);
  118. SkinItem *enumGroupDefOfType(const wchar_t *type, int n);
  119. SkinItem *getGroupDefAncestor(SkinItem *item);
  120. SkinItem *getContainerAncestor(SkinItem *item);
  121. //int getGroupDef(GUID g);
  122. SkinItem *getXuiGroupDef(const wchar_t *xuitag);
  123. int getObjectType(SkinItem *item);
  124. int getNumObject(); // total number of objects
  125. int getNumObject(int object_type); // return the number of objects of this type
  126. SkinItem *getObject(int object_type, int nth); // get nth object_type, return its index
  127. SkinItem *getContainerById(const wchar_t *id);
  128. int getObjectIdx(SkinItem *item);
  129. void reset(void);
  130. PtrList<GuiTreeItem> *getList();;
  131. PtrList<GuiTreeItem> *getGroupList();;
  132. void removeSkinPart(int scriptid);
  133. void deferredInvalidateGroup(const wchar_t *id);
  134. void deferredInvalidateType(const wchar_t *type);
  135. int timerclient_onDeferredCallback(intptr_t param1, intptr_t param2);
  136. SkinItem *getLastDefinedGroup() { return lastdefinedgroupdef; }
  137. SkinItem *enumGroupDef(int n) { return groupdefs.enumItem(n); }
  138. int getNumGroupDefs() { return groupdefs.getNumItems(); }
  139. private:
  140. int cached;
  141. int cachedtype;
  142. PtrList<GuiTreeItem> list;
  143. PtrListInsertMultiSorted<GuiTreeItem, SortGuiTreeItem> groupdefs;
  144. // PtrListQuickMultiSorted<GuiTreeItem, SortGuiTreeItemByGuid> groupdefsbyguid;
  145. PtrListQuickMultiSorted<GuiTreeItem, SortGuiTreeItemByXuiTag> xuigroupdefs;
  146. PtrListQuickMultiSorted<GuiTreeItem, SortGuiTreeItem> containers_by_id;
  147. PtrList<GuiTreeItem> wndtypes;
  148. int cached_guid_idx;
  149. GUID cached_guid;
  150. SkinItem *lastdefinedgroupdef;
  151. };
  152. extern GuiTree *guiTree;
  153. #endif