aboutsummaryrefslogtreecommitdiff
path: root/Src/Wasabi/api/wnd/wndclass/tabsheetbar.cpp
blob: f31dbc731c4d2bf9d149f5f132297e4883a131d9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "precomp.h"
#include "tabsheetbar.h"
#include "tabsheet.h"
#include "../notifmsg.h"

TabSheetBar::TabSheetBar() {
  margin = 0;
  spacing = -4;
  maxheightsofar = 0;
  bottombar.setParent(this);
}

TabSheetBar::~TabSheetBar() 
{
  btns.deleteAll();
}           

int TabSheetBar::onInit() {
  int rt = TABSHEETBAR_PARENT::onInit();

  bottombar.setContent(L"wasabi.tabsheet.nobutton.group");
  bottombar.init(this);

  foreach(btns) 
    GroupTabButton *gtb = btns.getfor();
    gtb->setParent(this);
    if (!gtb->isInited()) {
      gtb->init(this);
    }
    if (foreach_index == 0) 
      gtb->setStatus(STATUS_ON);
    else
      gtb->setStatus(STATUS_OFF);
    int h = gtb->getPreferences(SUGGESTED_H);
    if (h == AUTOWH) h = maxheightsofar;
    maxheightsofar = MAX(maxheightsofar, h);
  endfor;

  return rt;
}

void TabSheetBar::addChild(GroupTabButton *child) {
  ASSERT(!btns.haveItem(child));
  btns.addItem(child);
  if (isInited()) {
    child->setParent(this);
    if (!child->isInited()) {
      child->init(this);
    }
    int h = child->getPreferences(SUGGESTED_H);
    if (h == AUTOWH) h = maxheightsofar;
    maxheightsofar = MAX(maxheightsofar, h);
    onResize();
  }
  if (btns.getNumItems() == 1) 
    child->setStatus(STATUS_ON);
  else
    child->setStatus(STATUS_OFF);
}

int TabSheetBar::getHeight() {
  return maxheightsofar;
}

int TabSheetBar::onResize() {
  int rt = TABSHEETBAR_PARENT::onResize();
  GroupTabButton *selected=NULL;
  foreach(btns) 
    if (btns.getfor()->getStatus() == STATUS_ON) {
      selected = btns.getfor();
      break;
    }
  endfor;
  if (selected == NULL) selected = btns.getFirst();

  RECT r;
  getClientRect(&r);

  int x = margin;

  foreach(btns) 
    GroupTabButton *gtb = btns.getfor();

    int w = gtb->getPreferences(SUGGESTED_W);
    if (w == AUTOWH) w = 66;

    RECT dr;
    dr.left = r.left + x;
    dr.top = r.top;
    dr.right = dr.left + w;
    dr.bottom = dr.top + getHeight();

    gtb->resize(&dr);

    x += w + spacing;
  endfor;

  x -= spacing;
  RECT dr;
  dr.left = r.left + x;
  dr.top = r.top;
  dr.right = r.right;
  dr.bottom = r.top + getHeight();
  bottombar.resize(&dr);

  if (selected != NULL)
    selected->bringToFront();

  return rt;
}

int TabSheetBar::childNotify(ifc_window *child, int msg, intptr_t param1/* =0 */, intptr_t param2/* =0 */) {
  if (msg == ChildNotify::GROUPCLICKTGBUTTON_CLICKED && btns.haveItem(static_cast<GroupTabButton *>(child))) {
    GroupToggleButton *but = NULL;
    foreach(btns)
      if (btns.getfor() != child) 
        btns.getfor()->setStatus(STATUS_OFF);
      else
        but = btns.getfor();
    endfor;
    if (but != NULL)
      but->setStatus(STATUS_ON);
    else
      (static_cast<GroupToggleButton *>(child))->setStatus(STATUS_ON);
    onResize();    
  }
 if (msg == ChildNotify::AUTOWHCHANGED && btns.haveItem(static_cast<GroupTabButton *>(child)) && isPostOnInit()) 
  onResize();
 return TABSHEETBAR_PARENT::childNotify(child, msg, param1, param2);
}