2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 buttonBarActive = true;
31 setBackgroundColour(Colour::VIEWBACKGROUND);
33 symbolLeft.setPosition(0, 4);
34 symbolLeft.nextColour = Colour::BUTTONBACKGROUND;
35 symbolLeft.nextSymbol = WSymbol::LEFTARROW;
38 symbolRight.setPosition(getWidth() - 28, 4);
39 symbolRight.nextColour = Colour::BUTTONBACKGROUND;
40 symbolRight.nextSymbol = WSymbol::RIGHTARROW;
46 for (UINT i = 0; i < tabs.size(); i++)
48 delete tabs[i].button;
52 void WTabBar::addTab(const char* name, Boxx* boxx)
58 for(UINT i = 0; i < strlen(name); i++)
60 td.nameWidth += charWidth(name[i]);
64 for(UINT i = 0; i < tabs.size(); i++) newButtonX += tabs[i].button->getWidth() + 10;
66 WButton* newButton = new WButton();
67 newButton->setText(name);
68 newButton->setPosition(newButtonX, 2);
69 newButton->setSize(td.nameWidth + 6, Surface::getFontHeight());
70 if ((newButtonX + newButton->getWidth()) > (getWidth() - 22)) newButton->setVisible(false);
73 boxx->setPosition(0, 34);
74 boxx->setSize(getWidth(), getHeight()-34);
77 td.button = newButton;
83 newButton->setActive(true);
84 boxx->setVisible(true);
88 newButton->setActive(false);
89 boxx->setVisible(false);
90 symbolRight.nextColour = Colour::SELECTHIGHLIGHT; // if this is the 2nd+ tab, ensure right arrow goes active
94 int WTabBar::handleCommand(int command)
96 // This returns 0 for not handled, and 1 for handled and please-update-me, 2 for handled-no-update
98 // if the focus is in a pane, send the command there
101 // Send the command to the pane
102 // Return code should be:
104 // 1 - handled - stop command here
105 // 4 - handled - pane is returning control to here
106 // FIXME standardise these
108 int paneRetCode = tabs[visiblePane].pane->handleCommand(command);
109 if (paneRetCode == 0)
113 else if (paneRetCode == 1)
118 else if (paneRetCode == 4)
120 buttonBarActive = true;
121 tabs[visiblePane].button->setActive(true);
122 if (visiblePane != 0) symbolLeft.nextColour = Colour::SELECTHIGHLIGHT;
123 if (visiblePane != tabs.size() - 1) symbolRight.nextColour = Colour::SELECTHIGHLIGHT;
133 case Remote::DF_LEFT:
136 if (!left()) return 2;
140 case Remote::DF_RIGHT:
143 if (!right()) return 2;
148 case Remote::DF_DOWN:
150 buttonBarActive = false;
151 tabs[visiblePane].button->dim();
152 symbolLeft.nextColour = Colour::BUTTONBACKGROUND;
153 symbolRight.nextColour = Colour::BUTTONBACKGROUND;
154 if (tabs[visiblePane].pane->handleCommand(command) == 1) // shouldn't return anything else at this point?!
165 // When there are too many tabs to display simultaneously, extend this to shift the tabs left and right
169 if (visiblePane == 0) return false;
170 tabs[visiblePane].button->setActive(false);
171 tabs[visiblePane].pane->setVisible(false);
173 tabs[visiblePane].button->setActive(true);
174 tabs[visiblePane].pane->setVisible(true);
176 if (visiblePane == 0) symbolLeft.nextColour = Colour::BUTTONBACKGROUND;
177 symbolRight.nextColour = Colour::SELECTHIGHLIGHT;
179 // Move the buttons..
180 if (tabs[visiblePane].button->getVisible() == false)
182 tabs[visiblePane].button->setVisible(true);
183 // We have gone << past the last visible button
184 UINT newButtonX = 22;
186 for(j = visiblePane; j < tabs.size(); j++) // start with the button just uncovered
188 if ((newButtonX + tabs[j].button->getWidth()) > (getWidth() - 22)) break; // this one too big.
189 tabs[j].button->setPosition(newButtonX, 2);
190 newButtonX += tabs[j].button->getWidth() + 10;
192 for(; j < tabs.size(); j++) // hide the rest
194 tabs[j].button->setVisible(false);
201 bool WTabBar::right()
203 if (visiblePane == tabs.size() - 1) return false;
204 tabs[visiblePane].button->setActive(false);
205 tabs[visiblePane].pane->setVisible(false);
207 tabs[visiblePane].button->setActive(true);
208 tabs[visiblePane].pane->setVisible(true);
210 if (visiblePane == tabs.size() - 1) symbolRight.nextColour = Colour::BUTTONBACKGROUND;
211 symbolLeft.nextColour = Colour::SELECTHIGHLIGHT;
213 // Move the buttons..
214 if (tabs[visiblePane].button->getVisible() == false)
216 tabs[visiblePane].button->setVisible(true);
217 // We have gone >> past the last visible button
218 // Move all buttons left, but need to work out which one to finally display as first on the left
219 UINT displayWidth = getWidth() - 44;
220 UINT widthSum = tabs[visiblePane].button->getWidth(); // start with width of newly shown button (on the right)
223 for(i = visiblePane - 1; i >= 0; i--)
225 widthSum += tabs[i].button->getWidth() + 10; // add on width needed to display also the previous button
226 if (widthSum > displayWidth) // then it's too much
233 for(i = 0; i < startWith; i++) // For each button to the left of startWith...
235 tabs[i].button->setVisible(false);
238 UINT newButtonX = 22;
239 for(UINT j = startWith; j <= visiblePane; j++) // startWith -> the one we just uncovered
241 tabs[j].button->setPosition(newButtonX, 2);
242 newButtonX += tabs[j].button->getWidth() + 10;