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