tabsheetbar.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #include "precomp.h"
  2. #include "tabsheetbar.h"
  3. #include "tabsheet.h"
  4. #include "../notifmsg.h"
  5. TabSheetBar::TabSheetBar() {
  6. margin = 0;
  7. spacing = -4;
  8. maxheightsofar = 0;
  9. bottombar.setParent(this);
  10. }
  11. TabSheetBar::~TabSheetBar()
  12. {
  13. btns.deleteAll();
  14. }
  15. int TabSheetBar::onInit() {
  16. int rt = TABSHEETBAR_PARENT::onInit();
  17. bottombar.setContent(L"wasabi.tabsheet.nobutton.group");
  18. bottombar.init(this);
  19. foreach(btns)
  20. GroupTabButton *gtb = btns.getfor();
  21. gtb->setParent(this);
  22. if (!gtb->isInited()) {
  23. gtb->init(this);
  24. }
  25. if (foreach_index == 0)
  26. gtb->setStatus(STATUS_ON);
  27. else
  28. gtb->setStatus(STATUS_OFF);
  29. int h = gtb->getPreferences(SUGGESTED_H);
  30. if (h == AUTOWH) h = maxheightsofar;
  31. maxheightsofar = MAX(maxheightsofar, h);
  32. endfor;
  33. return rt;
  34. }
  35. void TabSheetBar::addChild(GroupTabButton *child) {
  36. ASSERT(!btns.haveItem(child));
  37. btns.addItem(child);
  38. if (isInited()) {
  39. child->setParent(this);
  40. if (!child->isInited()) {
  41. child->init(this);
  42. }
  43. int h = child->getPreferences(SUGGESTED_H);
  44. if (h == AUTOWH) h = maxheightsofar;
  45. maxheightsofar = MAX(maxheightsofar, h);
  46. onResize();
  47. }
  48. if (btns.getNumItems() == 1)
  49. child->setStatus(STATUS_ON);
  50. else
  51. child->setStatus(STATUS_OFF);
  52. }
  53. int TabSheetBar::getHeight() {
  54. return maxheightsofar;
  55. }
  56. int TabSheetBar::onResize() {
  57. int rt = TABSHEETBAR_PARENT::onResize();
  58. GroupTabButton *selected=NULL;
  59. foreach(btns)
  60. if (btns.getfor()->getStatus() == STATUS_ON) {
  61. selected = btns.getfor();
  62. break;
  63. }
  64. endfor;
  65. if (selected == NULL) selected = btns.getFirst();
  66. RECT r;
  67. getClientRect(&r);
  68. int x = margin;
  69. foreach(btns)
  70. GroupTabButton *gtb = btns.getfor();
  71. int w = gtb->getPreferences(SUGGESTED_W);
  72. if (w == AUTOWH) w = 66;
  73. RECT dr;
  74. dr.left = r.left + x;
  75. dr.top = r.top;
  76. dr.right = dr.left + w;
  77. dr.bottom = dr.top + getHeight();
  78. gtb->resize(&dr);
  79. x += w + spacing;
  80. endfor;
  81. x -= spacing;
  82. RECT dr;
  83. dr.left = r.left + x;
  84. dr.top = r.top;
  85. dr.right = r.right;
  86. dr.bottom = r.top + getHeight();
  87. bottombar.resize(&dr);
  88. if (selected != NULL)
  89. selected->bringToFront();
  90. return rt;
  91. }
  92. int TabSheetBar::childNotify(ifc_window *child, int msg, intptr_t param1/* =0 */, intptr_t param2/* =0 */) {
  93. if (msg == ChildNotify::GROUPCLICKTGBUTTON_CLICKED && btns.haveItem(static_cast<GroupTabButton *>(child))) {
  94. GroupToggleButton *but = NULL;
  95. foreach(btns)
  96. if (btns.getfor() != child)
  97. btns.getfor()->setStatus(STATUS_OFF);
  98. else
  99. but = btns.getfor();
  100. endfor;
  101. if (but != NULL)
  102. but->setStatus(STATUS_ON);
  103. else
  104. (static_cast<GroupToggleButton *>(child))->setStatus(STATUS_ON);
  105. onResize();
  106. }
  107. if (msg == ChildNotify::AUTOWHCHANGED && btns.haveItem(static_cast<GroupTabButton *>(child)) && isPostOnInit())
  108. onResize();
  109. return TABSHEETBAR_PARENT::childNotify(child, msg, param1, param2);
  110. }