StabtypeControl.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. //font = \"adding:12,bold:1\"\
  31. SOUI::SWindow * win = FindChildByName2<SOUI::SWindow>(L"con");
  32. if (win)
  33. {
  34. //font=\"face:微软雅黑, size : 16\"
  35. SOUI::SStringW strXmlName;
  36. if (checked)
  37. {
  38. //<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>
  39. strXmlName.Format(L"<radio2 id=\"%d\" \
  40. size=\"0, -1\" \
  41. cursor=\"hand\" \
  42. colorText=\"#ffffff\"\
  43. colorTextPush=\"#ffffff\"\
  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=\"#ffffff\"\
  61. colorTextPush=\"#ffffff\"\
  62. align=\"center\"\
  63. cursor=\"hand\"\
  64. extend=\"5,0,0,0\" \
  65. tip=\"%s\" \
  66. animate=\"1\" \
  67. skin=\"skin_tyteselection\" \
  68. name=\"%d\" \
  69. weight=\"1\"\
  70. checked=\"0\"> \
  71. %s</radio2>", id, title, id, title);
  72. }
  73. win->CreateChildren(strXmlName);
  74. SOUI::SStringW strbutto;
  75. strbutto.Format(L"%d", id);
  76. SOUI::SRadioBox2* pButton =
  77. FindChildByName2<SOUI::SRadioBox2>(strbutto);
  78. pButton->GetEventSet()->subscribeEvent(SOUI::EVT_CMD,
  79. Subscriber(&StabtypeControl::OnBtnClick, this));
  80. }
  81. }
  82. // 创建控件:初始化 xml,绑定事件等等
  83. int StabtypeControl::OnCreate(LPCREATESTRUCT lpCreateStruct)
  84. {
  85. pugi::xml_document xmlDoc;
  86. SOUI::SStringW strXml = L"tabtype_control";
  87. if (!LOADXML(xmlDoc, strXml, L"LAYOUT")) {
  88. return E_FAIL;
  89. }
  90. pugi::xml_node itemXmlNode = xmlDoc.child(L"tabtypecontrol");
  91. if (!itemXmlNode) {
  92. return E_FAIL;
  93. }
  94. this->CreateChildren(itemXmlNode);
  95. return 0;
  96. }
  97. // 按钮点击响应
  98. bool StabtypeControl::OnBtnClick(SOUI::EventArgs* pEvt)
  99. {
  100. // 获取按钮名称,获取后缀数字
  101. SOUI::SWindow* pButton =
  102. SOUI::sobj_cast<SOUI::SWindow>(pEvt->sender);
  103. SOUI::SStringW strName = pButton->GetName();
  104. //SOUI::SStringW strIndex = strName.Right(1);
  105. INT nIndex = _wtoi(strName);
  106. // 发送全局的自定义消息
  107. EventTabtypeControl evt(this);
  108. evt.nIndex = nIndex;
  109. FireEvent(evt); // 激活事件 Fire!!!
  110. return true;
  111. }
  112. }