]> git.vomp.tv Git - vompclient.git/blob - wremoteconfig.cc
More compiler warning fixes
[vompclient.git] / wremoteconfig.cc
1 /*
2     Copyright 2007 Chris Tallon, Marten Richter
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 "wremoteconfig.h"
22
23 #include "remote.h"
24 #include "wsymbol.h"
25 #include "colour.h"
26 #include "i18n.h"
27 #include "boxstack.h"
28
29 WRemoteConfig::WRemoteConfig()
30 {
31   remote = Remote::getInstance();
32   learnmode = false;
33   active = false;
34
35   sl.setShowSelOption(false);
36   sl.setPosition(10, 30);
37   add(&sl);
38   initSelectList(true);
39 }
40
41 WRemoteConfig::~WRemoteConfig()
42 {
43 }
44
45 void WRemoteConfig::initSelectList(bool startup)
46 {
47   ULONG selection = 0;
48   ULONG top = 0;
49
50   if (!startup)
51   {
52     selection = sl.getCurrentOption();
53     top = sl.getTopOption();
54   }
55
56   sl.clear();
57   sl.addColumn(0);
58   sl.addColumn(150);
59   sl.addColumn(300);
60   
61   ULONG i;
62   for (i = 0; i < 256; i++)
63   {
64     const char * name = remote->CommandDesc((UCHAR)i);
65     if (name != NULL)
66     {
67       char *line = remote->CommandTranslateStr((UCHAR)i);
68       sl.addOption(line,i,0);
69     }
70   }
71   if (!startup)
72   {
73     sl.hintSetCurrent(selection);
74     sl.hintSetTop(top);
75   }
76 }
77
78 void WRemoteConfig::setSize(UINT w, UINT h)
79 {
80   Boxx::setSize(w, h);
81   sl.setSize(area.w - 20, area.h - 70);
82 }
83
84 void WRemoteConfig::draw()
85 {
86   Boxx::draw();
87   
88   drawText(tr("Command"), 15, 4, DrawStyle::LIGHTTEXT);
89   drawText(tr("Hard wired"), 165, 4, DrawStyle::LIGHTTEXT);
90   drawText(tr("User assignable"), 315, 4, DrawStyle::LIGHTTEXT);
91
92   if (learnmode)
93   {
94     drawText(tr("Learning! Press any hardwired key to exit."), 15, area.h - 30, DrawStyle::SELECTHIGHLIGHT);
95   }
96   else
97   {
98     drawText(tr("Press [ok] for learning or MENU to reset to defaults."), 15, area.h - 30, DrawStyle::LIGHTTEXT);
99   }
100 }
101
102 bool WRemoteConfig::mouseLBDOWN(int x, int y)
103 {
104     if (sl.mouseLBDOWN(x,y))
105     {
106       BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
107       return true;
108     }
109     return false;
110 }
111
112 bool WRemoteConfig::mouseMove(int x, int y) 
113 {
114     if (sl.mouseMove(x,y))
115     {
116       sl.setShowSelOption(true);
117       sl.draw();
118       return true;
119     }
120     return false;
121 }
122 /*
123 void WRemoteConfig::processMessage(Message* m)
124 {
125   Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
126
127   if (m->message == Message::MOUSE_MOVE)
128   {
129     if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
130     {
131       sl.setShowSelOption(true);
132       sl.draw();
133       viewman->updateView(this);
134     }
135   }
136   else if (m->message == Message::MOUSE_LBDOWN)
137   {
138     if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
139     {
140       ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
141     }
142     else
143     {
144       //check if press is outside this view! then simulate cancel
145       int x=(m->parameter>>16)-getScreenX();
146       int y=(m->parameter&0xFFFF)-getScreenY();
147       if (x<0 || y <0 || x>getWidth() || y>getHeight())
148       {
149         ViewMan::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
150       }
151     }
152   }
153 }
154 */
155
156 /*
157 void WRemoteConfig::doSave()
158 {
159     Message* m = new Message();
160     m->message = Message::CHANGED_REMOTECONTROL;
161     m->to = parent;
162     m->parameter = 0;
163     Command::getInstance()->postMessageNoLock(m);
164     
165 }
166 */
167
168 int WRemoteConfig::handleCommand(int command)
169 {
170   if (learnmode)
171   {
172     learnmode = false;
173     if (command == Remote::NA_LEARN)
174     {
175       initSelectList(false);
176     }
177     return 1;
178   }
179   switch(command)
180   {
181     case Remote::DF_UP:
182     case Remote::UP:
183     {
184       if (sl.getCurrentOption() != 0)
185       {
186         sl.up();
187         return 1;
188       }
189       else
190       {
191         sl.setShowSelOption(false);
192         active = false;
193         return 4; // return control to vopts
194       }
195     }
196     case Remote::DF_DOWN:
197     case Remote::DOWN:
198     {
199       if (!active)
200       {
201         active = true;    
202         sl.setShowSelOption(true);
203       }
204       else
205       {
206         sl.down();
207       }
208       return 1;
209     }
210     case Remote::SKIPBACK:
211     {
212       sl.pageUp();
213       return 1;
214     }
215     case Remote::SKIPFORWARD:
216     {
217       sl.pageDown();
218       return 1;
219     }
220     case Remote::OK:
221     {
222       learnmode = true;
223       remote->EnterLearningMode(sl.getCurrentOptionData());
224       return 1;
225     }
226     case Remote::BACK:
227     {
228       return 0;
229 /*
230       doSave();
231
232       // Instead of returning 4 here which would delete this view
233       // before the doSave message is processed, let the message queue
234       // do the doSave then this close message. That will make the options menu
235       // disappear before this view
236
237       Message* m = new Message();
238       m->message = Message::CLOSE_ME;
239       m->from = this;
240       m->to = viewman;
241       Command::getInstance()->postMessageNoLock(m);
242       return 2;
243 */      
244     }
245     case Remote::MENU:
246     {
247       remote->ResetToDefault();
248       initSelectList(false);
249       return 1;
250     }
251   }
252
253   return 0;
254 }
255
256