StabtypeControl.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #include "stdafx.h"
  2. #include "StabtypeControl.h"
  3. #include "SRadioBox2.h"
  4. namespace SOUI
  5. {
  6. StabtypeControl::StabtypeControl()
  7. {
  8. m_evtSet.addEvent(EVENTID(EventTabtypeControl));
  9. }
  10. StabtypeControl::~StabtypeControl()
  11. {
  12. }
  13. void StabtypeControl::DestroyWindowcon()
  14. {
  15. SOUI::SWindow * wins = FindChildByName2<SOUI::SWindow>(L"con");
  16. if (wins)
  17. {
  18. //remove all children at first.
  19. SWindow *pChild = wins->GetWindow(GSW_FIRSTCHILD);
  20. while (pChild)
  21. {
  22. SWindow *pNext = pChild->GetWindow(GSW_NEXTSIBLING);
  23. pChild->DestroyWindow();
  24. pChild = pNext;
  25. }
  26. }
  27. }
  28. void StabtypeControl::ItemCreateChildren(int id, SStringW title,bool checked)
  29. {
  30. SOUI::SWindow * win = FindChildByName2<SOUI::SWindow>(L"con");
  31. if (win)
  32. {
  33. //font=\"face:微软雅黑, size : 16\"
  34. SOUI::SStringW strXmlName;
  35. if (checked)
  36. {
  37. //<radio2 size="0,-1" name="" colorTextPush="#D8D8D8" colorText="#D8D8D844" font="adding:12,bold:1" checked="1" skin="skin_tyteselection" align="center" weight="1" extend="0,0,0,0" >US</radio2>
  38. strXmlName.Format(L"<radio2 id=\"%d\" \
  39. size=\"0, -1\" \
  40. cursor=\"hand\" \
  41. colorText=\"#D8D8D844\"\
  42. colorTextPush=\"#D8D8D8\"\
  43. font=\"adding:12,bold:1\"\
  44. align=\"center\"\
  45. cursor=\"hand\"\
  46. extend=\"0,0,0,0\" \
  47. tip=\"%s\" \
  48. animate=\"1\" \
  49. skin=\"skin_tyteselection\" \
  50. name=\"%d\" \
  51. weight=\"1\"\
  52. checked=\"1\"> \
  53. %s</radio2>", id, title, id, title);
  54. }
  55. else
  56. {
  57. strXmlName.Format(L"<radio2 id=\"%d\" \
  58. size=\"0, -1\" \
  59. cursor=\"hand\" \
  60. colorText=\"#D8D8D844\"\
  61. colorTextPush=\"#D8D8D8\"\
  62. font=\"adding:12,bold:1\"\
  63. align=\"center\"\
  64. cursor=\"hand\"\
  65. extend=\"5,0,0,0\" \
  66. tip=\"%s\" \
  67. animate=\"1\" \
  68. skin=\"skin_tyteselection\" \
  69. name=\"%d\" \
  70. weight=\"1\"\
  71. checked=\"0\"> \
  72. %s</radio2>", id, title, id, title);
  73. }
  74. win->CreateChildren(strXmlName);
  75. SOUI::SStringW strbutto;
  76. strbutto.Format(L"%d", id);
  77. SOUI::SRadioBox2* pButton =
  78. FindChildByName2<SOUI::SRadioBox2>(strbutto);
  79. pButton->GetEventSet()->subscribeEvent(SOUI::EVT_CMD,
  80. Subscriber(&StabtypeControl::OnBtnClick, this));
  81. }
  82. }
  83. // 创建控件:初始化 xml,绑定事件等等
  84. int StabtypeControl::OnCreate(LPCREATESTRUCT lpCreateStruct)
  85. {
  86. pugi::xml_document xmlDoc;
  87. SOUI::SStringW strXml = L"tabtype_control";
  88. if (!LOADXML(xmlDoc, strXml, L"LAYOUT")) {
  89. return E_FAIL;
  90. }
  91. pugi::xml_node itemXmlNode = xmlDoc.child(L"tabtypecontrol");
  92. if (!itemXmlNode) {
  93. return E_FAIL;
  94. }
  95. this->CreateChildren(itemXmlNode);
  96. return 0;
  97. }
  98. // 按钮点击响应
  99. bool StabtypeControl::OnBtnClick(SOUI::EventArgs* pEvt)
  100. {
  101. // 获取按钮名称,获取后缀数字
  102. SOUI::SWindow* pButton =
  103. SOUI::sobj_cast<SOUI::SWindow>(pEvt->sender);
  104. SOUI::SStringW strName = pButton->GetName();
  105. //SOUI::SStringW strIndex = strName.Right(1);
  106. INT nIndex = _wtoi(strName);
  107. // 发送全局的自定义消息
  108. EventTabtypeControl evt(this);
  109. evt.nIndex = nIndex;
  110. FireEvent(evt); // 激活事件 Fire!!!
  111. return true;
  112. }
  113. }