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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 buttonBarActive = true;
31 setBackgroundColour(DrawStyle::TABVIEWBACKGROUND);
33 symbolLeft.setPosition(0, 4);
34 symbolLeft.nextColour = DrawStyle::BUTTONBACKGROUND;
35 symbolLeft.nextSymbol = WSymbol::LEFTARROW;
38 symbolRight.setPosition(0, 4); // will be reset in addtab
39 symbolRight.nextColour = DrawStyle::BUTTONBACKGROUND;
40 symbolRight.nextSymbol = WSymbol::RIGHTARROW;
46 for (UINT i = 0; i < tabs.size(); i++)
48 delete tabs[i].button;
49 delete tabs[i].pane; //moved from vopts MR
53 void WTabBar::addTab(const char* name, Boxx* boxx)
59 for(UINT i = 0; i < strlen(name); i++)
61 td.nameWidth += (UINT)charWidth(name[i]);
65 for(UINT i = 0; i < tabs.size(); i++) newButtonX += tabs[i].button->getWidth() + 10;
67 WButton* newButton = new WButton();
68 newButton->setText(name);
69 newButton->setPosition(newButtonX, 2);
70 newButton->setSize(td.nameWidth + 6, getFontHeight());
71 if ((newButtonX + newButton->getWidth()) > (getWidth() - 22)) newButton->setVisible(false);
74 boxx->setPosition(0, 34);
75 boxx->setSize(getWidth(), getHeight()-34);
78 td.button = newButton;
84 newButton->setActive(true);
85 boxx->setVisible(true);
89 newButton->setActive(false);
90 boxx->setVisible(false);
91 symbolRight.nextColour = DrawStyle::SELECTHIGHLIGHT; // if this is the 2nd+ tab, ensure right arrow goes active
94 // WTabbar doesn't know its width during the constructor
95 // So this is moved to here for now
96 symbolRight.setPosition(getWidth() - 28, 4);
99 int WTabBar::handleCommand(int command)
101 // This returns 0 for not handled, and 1 for handled and please-update-me, 2 for handled-no-update
103 // if the focus is in a pane, send the command there
104 if (!buttonBarActive)
106 // Send the command to the pane
107 // Return code should be:
109 // 1 - handled - stop command here
110 // 4 - handled - pane is returning control to here
111 // 5 - activate button bar and let button process the call, this for simple up and down scroll views
112 // FIXME standardise these
114 int paneRetCode = tabs[visiblePane].pane->handleCommand(command);
115 if (paneRetCode == 0)
119 else if (paneRetCode == 1)
124 else if (paneRetCode == 4)
126 buttonBarActive = true;
127 tabs[visiblePane].button->setActive(true);
128 if (visiblePane != 0) symbolLeft.nextColour = DrawStyle::SELECTHIGHLIGHT;
129 if (visiblePane != tabs.size() - 1) symbolRight.nextColour = DrawStyle::SELECTHIGHLIGHT;
132 } else if (paneRetCode == 5)
134 buttonBarActive = true;
135 tabs[visiblePane].button->setActive(true);
136 if (visiblePane != 0) symbolLeft.nextColour = DrawStyle::SELECTHIGHLIGHT;
137 if (visiblePane != tabs.size() - 1) symbolRight.nextColour = DrawStyle::SELECTHIGHLIGHT;
147 case Remote::DF_LEFT:
150 if (!left()) return 2;
154 case Remote::DF_RIGHT:
157 if (!right()) return 2;
164 case Remote::DF_DOWN:
166 int handleResult = tabs[visiblePane].pane->handleCommand(command);
167 // A WOptionPane will accept control being passed into it from inactive, up or down (== 1).
168 // A WTextBox will only accept control if it will scroll (== 1). It will refuse if not (== 4).
170 if (handleResult == 1)
172 buttonBarActive = false;
173 tabs[visiblePane].button->dim();
174 symbolLeft.nextColour = DrawStyle::BUTTONBACKGROUND;
175 symbolRight.nextColour = DrawStyle::BUTTONBACKGROUND;
179 else if (handleResult == 4)
186 Log::getInstance()->log("WTabBar", Log::ERR, "Up/Down client returned not 1 or 4");
194 // When there are too many tabs to display simultaneously, extend this to shift the tabs left and right
198 if (visiblePane == 0) return false;
199 tabs[visiblePane].button->setActive(false);
200 tabs[visiblePane].pane->setVisible(false);
202 tabs[visiblePane].button->setActive(true);
203 tabs[visiblePane].pane->setVisible(true);
205 if (visiblePane == 0) symbolLeft.nextColour = DrawStyle::BUTTONBACKGROUND;
206 symbolRight.nextColour = DrawStyle::SELECTHIGHLIGHT;
208 // Move the buttons..
209 if (tabs[visiblePane].button->getVisible() == false)
211 tabs[visiblePane].button->setVisible(true);
212 // We have gone << past the last visible button
213 UINT newButtonX = 22;
215 for(j = visiblePane; j < tabs.size(); j++) // start with the button just uncovered
217 if ((newButtonX + tabs[j].button->getWidth()) > (getWidth() - 22)) break; // this one too big.
218 tabs[j].button->setPosition(newButtonX, 2);
219 newButtonX += tabs[j].button->getWidth() + 10;
221 for(; j < tabs.size(); j++) // hide the rest
223 tabs[j].button->setVisible(false);
230 bool WTabBar::right()
232 if (visiblePane == tabs.size() - 1) return false;
233 tabs[visiblePane].button->setActive(false);
234 tabs[visiblePane].pane->setVisible(false);
236 tabs[visiblePane].button->setActive(true);
237 tabs[visiblePane].pane->setVisible(true);
239 if (visiblePane == tabs.size() - 1) symbolRight.nextColour = DrawStyle::BUTTONBACKGROUND;
240 symbolLeft.nextColour = DrawStyle::SELECTHIGHLIGHT;
242 // Move the buttons..
243 if (tabs[visiblePane].button->getVisible() == false)
245 tabs[visiblePane].button->setVisible(true);
246 // We have gone >> past the last visible button
247 // Move all buttons left, but need to work out which one to finally display as first on the left
248 UINT displayWidth = getWidth() - 44;
249 UINT widthSum = tabs[visiblePane].button->getWidth(); // start with width of newly shown button (on the right)
252 for(i = visiblePane - 1; i >= 0; i--)
254 widthSum += tabs[i].button->getWidth() + 10; // add on width needed to display also the previous button
255 if (widthSum > displayWidth) // then it's too much
262 for(i = 0; i < startWith; i++) // For each button to the left of startWith...
264 tabs[i].button->setVisible(false);
267 UINT newButtonX = 22;
268 for(UINT j = startWith; j <= visiblePane; j++) // startWith -> the one we just uncovered
270 tabs[j].button->setPosition(newButtonX, 2);
271 newButtonX += tabs[j].button->getWidth() + 10;
278 bool WTabBar::mouseMove(int x, int y) {
279 if (tabs[visiblePane].pane->mouseMove(x,y)) {
280 if (buttonBarActive){
281 buttonBarActive = false;
282 tabs[visiblePane].button->dim();
283 symbolLeft.nextColour = DrawStyle::BUTTONBACKGROUND;
284 symbolRight.nextColour = DrawStyle::BUTTONBACKGROUND;
293 bool WTabBar::mouseAndroidScroll(int x, int y, int sx, int sy) {
294 if (tabs[visiblePane].pane->mouseAndroidScroll(x, y,sx,sy)) {
301 bool WTabBar::mouseLBDOWN(int x, int y) {
303 for (i=0;i<tabs.size();i++) {
304 if (tabs[i].button->getVisible()) {
305 if (tabs[i].button->mouseMove(x,y)) {
306 tabs[visiblePane].button->setActive(false);
307 tabs[visiblePane].pane->setVisible(false);
308 tabs[visiblePane].pane->deactivateAllControls();
310 tabs[visiblePane].button->setActive(true);
311 tabs[visiblePane].pane->setVisible(true);
312 tabs[visiblePane].pane->deactivateAllControls();
313 buttonBarActive = true;
319 if (tabs[visiblePane].pane->mouseLBDOWN(x,y)) {
320 buttonBarActive = false;
321 tabs[visiblePane].button->dim();
322 symbolLeft.nextColour = DrawStyle::BUTTONBACKGROUND;
323 symbolRight.nextColour = DrawStyle::BUTTONBACKGROUND;
327 if (symbolLeft.mouseLBDOWN(x,y)) {
332 if (symbolRight.mouseLBDOWN(x,y)) {
340 void WTabBar::activateFocus(bool active)
344 tabs[visiblePane].button->setActive(true);
345 buttonBarActive = true;
348 tabs[visiblePane].button->setActive(false);
349 buttonBarActive = false;