]> git.vomp.tv Git - vompclient.git/blob - vchannellist.cc
Mouse code for windows
[vompclient.git] / vchannellist.cc
1 /*
2     Copyright 2004-2007 Chris Tallon
3
4     This file is part of VOMP.
5
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.
10
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.
15
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.
19 */
20
21 #include "vchannellist.h"
22
23 #include "remote.h"
24 #include "wsymbol.h"
25 #include "vvideolive.h"
26 #include "vvideolivetv.h"
27 #include "colour.h"
28 #include "video.h"
29 #include "i18n.h"
30 #include "channel.h"
31 #include "message.h"
32 #include "boxstack.h"
33 #include "vchannelselect.h"
34
35 VChannelList::VChannelList(ULONG type)
36 {
37   boxstack = BoxStack::getInstance();
38   setSize(570, 420);
39   createBuffer();
40   if (Video::getInstance()->getFormat() == Video::PAL)
41   {
42     setPosition(80, 70);
43   }
44   else
45   {
46     setPosition(70, 35);
47   }
48
49   setTitleBarOn(1);
50
51   if (type == VDR::VIDEO)
52   {
53     setTitleText(tr("Channels"));
54   }
55   else if (type == VDR::RADIO)
56   {
57     setTitleText(tr("Radio Stations"));
58   }
59   setTitleBarColour(Colour::TITLEBARBACKGROUND);
60
61   sl.setPosition(10, 30 + 5);
62   sl.setSize(area.w - 20, area.h - 30 - 15 - 30);
63   add(&sl);
64 }
65
66 VChannelList::~VChannelList()
67 {
68   if (chanList)
69   {
70     for (UINT i = 0; i < chanList->size(); i++)
71     {
72       delete (*chanList)[i];
73     }
74
75     chanList->clear();
76     delete chanList;
77   }
78 }
79
80 void VChannelList::setList(ChannelList* tlist)
81 {
82   char str[500];
83
84   sl.addColumn(0);
85   sl.addColumn(60);
86
87   chanList = tlist;
88
89   Channel* chan;
90   int first = 1;
91   if (chanList)
92   {
93     for (UINT i = 0; i < chanList->size(); i++)
94     {
95       chan = (*chanList)[i];
96       sprintf(str, "%lu\t%s", chan->number, chan->name);
97       chan->index = sl.addOption(str, (ULONG)chan, first);
98       first = 0;
99     }
100   }
101 }
102
103 void VChannelList::highlightChannel(Channel* chan)
104 {
105   sl.hintSetCurrent(chan->index);
106   sl.draw();
107   doShowingBar();
108   boxstack->update(this);
109 }
110
111 void VChannelList::draw()
112 {
113   TBBoxx::draw();
114   sl.draw();
115
116   // Put the status stuff at the bottom
117
118   WSymbol w;
119   TEMPADD(&w);
120
121   w.nextSymbol = WSymbol::UP;
122   w.setPosition(20, 385);
123   w.draw();
124
125   w.nextSymbol = WSymbol::DOWN;
126   w.setPosition(50, 385);
127   w.draw();
128
129   w.nextSymbol = WSymbol::SKIPBACK;
130   w.setPosition(85, 385);
131   w.draw();
132
133   w.nextSymbol = WSymbol::SKIPFORWARD;
134   w.setPosition(115, 385);
135   w.draw();
136
137   w.nextSymbol = WSymbol::PLAY;
138   w.setPosition(150, 385);
139   w.draw();
140
141   doShowingBar();
142 }
143
144 void VChannelList::doShowingBar()
145 {
146   int topOption = sl.getTopOption() + 1;
147   if (sl.getNumOptions() == 0) topOption = 0;
148
149   char showing[200];
150   sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
151
152   rectangle(220, 385, 220+160, 385+25, Colour::VIEWBACKGROUND);
153   drawText(showing, 220, 385, Colour::LIGHTTEXT);
154 }
155
156 int VChannelList::handleCommand(int command)
157 {
158   switch(command)
159   {
160     case Remote::DF_UP:
161     case Remote::UP:
162     {
163       sl.up();
164       sl.draw();
165
166       doShowingBar();
167       boxstack->update(this);
168       return 2;
169     }
170     case Remote::DF_DOWN:
171     case Remote::DOWN:
172     {
173       sl.down();
174       sl.draw();
175
176       doShowingBar();
177       boxstack->update(this);
178       return 2;
179     }
180     case Remote::SKIPBACK:
181     {
182       sl.pageUp();
183       sl.draw();
184
185       doShowingBar();
186       boxstack->update(this);
187       return 2;
188     }
189     case Remote::SKIPFORWARD:
190     {
191       sl.pageDown();
192       sl.draw();
193
194       doShowingBar();
195       boxstack->update(this);
196       return 2;
197     }
198     case Remote::ZERO:
199     case Remote::ONE:
200     case Remote::TWO:
201     case Remote::THREE:
202     case Remote::FOUR:
203     case Remote::FIVE:
204     case Remote::SIX:
205     case Remote::SEVEN:
206     case Remote::EIGHT:
207     case Remote::NINE:
208     {
209       VChannelSelect* v = new VChannelSelect(this);
210       v->draw();
211       boxstack->add(v);
212       boxstack->update(v);
213       v->handleCommand(command);
214       return 2;
215     }
216     case Remote::OK:
217     case Remote::PLAY:
218     {
219       Channel* chan = NULL;
220       if (chanList) chan = (Channel*)sl.getCurrentOptionData();
221       if (chan == NULL) return 2;
222  
223 //      if (chan->type == VDR::VIDEO)
224 //      {
225         VVideoLiveTV* v = new VVideoLiveTV(chanList, chan->number, this);
226         boxstack->add(v);
227         v->go();
228 /*
229       }
230       else
231       {
232         VVideoLive* v = new VVideoLive(chanList, chan->type, this);
233         v->draw();
234         boxstack->add(v);
235         boxstack->update(v);
236         v->channelChange(VVideoLive::NUMBER, chan->number);
237       }
238 */
239       return 2;
240     }
241     case Remote::BACK:
242     {
243       return 4;
244     }
245   }
246   // stop command getting to any more views
247   return 1;
248 }
249
250 void VChannelList::processMessage(Message* m)
251 {
252   if (m->message == Message::MOUSE_MOVE)
253   {
254     if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
255     {
256       sl.draw();
257       doShowingBar();
258       boxstack->update(this);
259     }
260   }
261   else if (m->message == Message::MOUSE_LBDOWN)
262   {
263     if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
264     {
265       boxstack->handleCommand(Remote::OK); //simulate OK press
266     }
267     else
268     { //check if press is outside this view! then simulate cancel
269       int x=(m->parameter>>16)-getScreenX();
270       int y=(m->parameter&0xFFFF)-getScreenY();
271       if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
272       {
273         boxstack->handleCommand(Remote::BACK); //simulate cancel press
274       }
275     }
276   }
277   else if (m->message == Message::CHANNEL_CHANGE)
278   {
279     Channel* chan = NULL;
280     for (UINT i = 0; i < chanList->size(); i++)
281     {
282       if ((*chanList)[i]->number == m->parameter)
283       {
284         chan = (*chanList)[i];
285         break;
286       }
287     }
288     if (!chan) return;
289
290     if (chan->type == VDR::VIDEO)
291     {
292       VVideoLiveTV* v = new VVideoLiveTV(chanList, chan->number, this);
293       boxstack->add(v);
294       v->go();    
295     }
296     else
297     {
298     /*
299       VVideoLive* v = new VVideoLive(chanList, chan->type, this);
300       v->draw();
301       boxstack->add(v);
302       boxstack->update(v);
303       v->channelChange(VVideoLive::NUMBER, chan->number);
304     */
305     }
306   }
307 }