]> git.vomp.tv Git - vompclient.git/blob - wremoteconfig.cc
Switch trunk code to new boxes
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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
28 WRemoteConfig::WRemoteConfig()
29 {
30   remote = Remote::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, Colour::LIGHTTEXT);
88   drawText(tr("Hard wired"), 165, 4, Colour::LIGHTTEXT);
89   drawText(tr("User assignable"), 315, 4, Colour::LIGHTTEXT);
90
91   if (learnmode)
92   {
93     drawText(tr("Learning! Press any hardwired key to exit!"), 15, area.h - 30, Colour::SELECTHIGHLIGHT);
94   }
95   else
96   {
97     drawText(tr("Press [ok] for learning or MENU to reset to defaults! "), 15, area.h - 30, Colour::LIGHTTEXT);
98   }
99 }
100
101 /*
102 void WRemoteConfig::processMessage(Message* m)
103 {
104   Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
105
106   if (m->message == Message::MOUSE_MOVE)
107   {
108     if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
109     {
110       sl.setShowSelOption(true);
111       sl.draw();
112       viewman->updateView(this);
113     }
114   }
115   else if (m->message == Message::MOUSE_LBDOWN)
116   {
117     if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
118     {
119       ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
120     }
121     else
122     {
123       //check if press is outside this view! then simulate cancel
124       int x=(m->parameter>>16)-getScreenX();
125       int y=(m->parameter&0xFFFF)-getScreenY();
126       if (x<0 || y <0 || x>getWidth() || y>getHeight())
127       {
128         ViewMan::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
129       }
130     }
131   }
132 }
133 */
134
135 /*
136 void WRemoteConfig::doSave()
137 {
138     Message* m = new Message();
139     m->message = Message::CHANGED_REMOTECONTROL;
140     m->to = parent;
141     m->parameter = 0;
142     Command::getInstance()->postMessageNoLock(m);
143     
144 }
145 */
146
147 int WRemoteConfig::handleCommand(int command)
148 {
149   if (learnmode)
150   {
151     learnmode = false;
152     if (command == Remote::NA_LEARN)
153     {
154       initSelectList(false);
155     }
156     return 1;
157   }
158   switch(command)
159   {
160     case Remote::DF_UP:
161     case Remote::UP:
162     {
163       if (sl.getCurrentOption() != 0)
164       {
165         sl.up();
166         return 1;
167       }
168       else
169       {
170         sl.setShowSelOption(false);
171         active = false;
172         return 4; // return control to vopts
173       }
174     }
175     case Remote::DF_DOWN:
176     case Remote::DOWN:
177     {
178       if (!active)
179       {
180         active = true;    
181         sl.setShowSelOption(true);
182       }
183       else
184       {
185         sl.down();
186       }
187       return 1;
188     }
189     case Remote::SKIPBACK:
190     {
191       sl.pageUp();
192       return 1;
193     }
194     case Remote::SKIPFORWARD:
195     {
196       sl.pageDown();
197       return 1;
198     }
199     case Remote::OK:
200     {
201       learnmode = true;
202       remote->EnterLearningMode(sl.getCurrentOptionData());
203       return 1;
204     }
205     case Remote::BACK:
206     {
207       return 0;
208 /*
209       doSave();
210
211       // Instead of returning 4 here which would delete this view
212       // before the doSave message is processed, let the message queue
213       // do the doSave then this close message. That will make the options menu
214       // disappear before this view
215
216       Message* m = new Message();
217       m->message = Message::CLOSE_ME;
218       m->from = this;
219       m->to = viewman;
220       Command::getInstance()->postMessageNoLock(m);
221       return 2;
222 */      
223     }
224     case Remote::MENU:
225     {
226       remote->ResetToDefault();
227       initSelectList(false);
228       return 1;
229     }
230   }
231
232   return 0;
233 }
234
235