string.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. //
  4. //
  5. //////////////////////////////////////////////////////////////////////////////
  6. class StringItem : public IObject {
  7. private:
  8. TRef<StringItem> m_pnext;
  9. ZString m_str;
  10. public:
  11. StringItem(const ZString& str, StringItem* pnext) :
  12. m_str(str),
  13. m_pnext(pnext)
  14. {
  15. }
  16. StringItem* GetNext()
  17. {
  18. return m_pnext;
  19. }
  20. const ZString& GetString()
  21. {
  22. return m_str;
  23. }
  24. };
  25. class StringList : public List {
  26. private:
  27. TRef<EventSourceImpl> m_peventSource;
  28. TRef<StringItem> m_pitem;
  29. int m_count;
  30. public:
  31. StringList() :
  32. m_count(0)
  33. {
  34. m_peventSource = new EventSourceImpl();
  35. }
  36. void AddItem(const ZString& str)
  37. {
  38. m_count++;
  39. m_pitem = new StringItem(str, m_pitem);
  40. m_peventSource->Trigger();
  41. }
  42. //
  43. // IList
  44. //
  45. int GetCount()
  46. {
  47. return m_count;
  48. }
  49. ItemID GetItem(int index)
  50. {
  51. ZAssert(index >= 0);
  52. if (index < m_count) {
  53. StringItem* pitem = m_pitem;
  54. while (index > 0) {
  55. pitem = pitem->GetNext();
  56. index--;
  57. }
  58. return pitem;
  59. } else {
  60. return NULL;
  61. }
  62. }
  63. int GetIndex(ItemID pitemFind)
  64. {
  65. StringItem* pitem = m_pitem;
  66. int index = 0;
  67. while (pitem != NULL) {
  68. if ((ItemID)pitem == pitemFind) {
  69. return index;
  70. }
  71. pitem = pitem->GetNext();
  72. index++;
  73. }
  74. return -1;
  75. }
  76. ItemID GetNext(ItemID pitem)
  77. {
  78. return ((StringItem*)pitem)->GetNext();
  79. }
  80. IEventSource* GetChangedEvent()
  81. {
  82. return m_peventSource;
  83. }
  84. };
  85. class StringItemPainter : public ItemPainter {
  86. public:
  87. int GetXSize()
  88. {
  89. return 64;
  90. }
  91. int GetYSize()
  92. {
  93. return 12;
  94. }
  95. void Paint(ItemID pitemArg, Surface* psurface, bool bSelected, bool bFocus)
  96. {
  97. StringItem* pitem = (StringItem*)pitemArg;
  98. if (bSelected) {
  99. psurface->FillRect(
  100. WinRect(0, 0, 64, 10),
  101. Color(0, 0, 0.5f)
  102. );
  103. }
  104. psurface->DrawString(
  105. WinPoint(0, 0),
  106. pitem->GetString()
  107. );
  108. }
  109. };