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, see <https://www.gnu.org/licenses/>.
25 #include "messagequeue.h"
27 #include "vchannelselect.h"
29 // this class only works as it does because the remote command
30 // values for the numbers are the numbers themselves !
32 VChannelSelect::VChannelSelect(MessageReceiver* v)
38 numWidth = VDR::getInstance()->getChannelNumberWidth();
39 if (numWidth > 10) numWidth = 10;
40 for (int i = 0; i < numWidth; i++) input[i] = -1;
42 setSize((numWidth*10) + 22, 30); // 10 px = width of number chars in font
45 setBackgroundColour(DrawStyle::VIEWBACKGROUND);
48 VChannelSelect::~VChannelSelect()
50 Timers::getInstance()->cancelTimer(this, 1);
53 void VChannelSelect::timercall(int /*clientReference*/)
55 if (ignoreTimer) return;
59 void VChannelSelect::doInput(int number)
61 for (int i = numGot - 1; i >= 0; i--)
63 input[i+1] = input[i];
70 void VChannelSelect::draw()
77 for (int i = 0; i < numWidth; i++)
81 drawText("_", 7 + ((numWidth - 1 - i) * 10), 5, DrawStyle::LIGHTTEXT);
85 sprintf(text, "%i", input[i]);
86 drawText(text, 7 + ((numWidth - 1 - i) * 10), 5, DrawStyle::LIGHTTEXT);
91 void VChannelSelect::changeChannel()
94 Timers::getInstance()->cancelTimer(this, 1);
98 // Is there valid data? (is any number not-zero)
100 for(i = 0; i < numWidth; i++) if (input[i]) break;
102 if (i < numWidth) // There is data
107 m->message = Message::CHANNEL_CHANGE;
110 for(i = numGot - 1; i >= 0; i--)
112 m->parameter += input[i] * static_cast<u4>(pow(10., i));
115 MessageQueue::getInstance()->postMessage(m);
119 m = new Message(); // Delete self
121 m->p_to = Message::BOXSTACK;
122 m->message = Message::CLOSE_ME;
123 MessageQueue::getInstance()->postMessage(m);
126 int VChannelSelect::handleCommand(int command)
143 BoxStack::getInstance()->update(this);
144 if (numGot == numWidth) changeChannel();
145 else Timers::getInstance()->setTimerD(this, 1, 3);
146 return BoxStack::COMMAND_HANDLED;
151 return BoxStack::COMMAND_HANDLED;
155 // allow command to drop through to other views
156 return BoxStack::DROP_THROUGH;