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