2 Copyright 2007-2020 Chris Tallon, Marten Richter
4 This file is part of VOMP.
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.
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.
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/>.
29 #include "wremoteconfig.h"
33 WRemoteConfig::WRemoteConfig()
35 remote = InputMan::getInstance();
39 sl.setShowSelOption(false);
40 sl.setPosition(10, 30);
45 WRemoteConfig::~WRemoteConfig()
49 void WRemoteConfig::initSelectList(bool startup)
51 InputMan* inputMan = InputMan::getInstance();
58 selection = sl.getCurrentOption();
59 top = sl.getTopOption();
67 for (UINT i = 0; i < 256; i++)
69 const char* vompKeyName = InputMan::getVompKeyName(static_cast<UCHAR>(i));
70 if (vompKeyName != NULL)
76 line += inputMan->getHardCodedHardwareKeyNamesForVompKey(static_cast<UCHAR>(i));
77 line += " \t"; // FIXME extra spaces for braindead strtok. Ditch strtok.
78 line += inputMan->getAllHardwareKeyNamesAssignedToVompKey(static_cast<UCHAR>(i));
79 sl.addOption(line.c_str(), reinterpret_cast<void*>(i), 0);
85 sl.hintSetCurrent(selection);
90 void WRemoteConfig::setSize(UINT w, UINT h)
93 sl.setSize(area.w - 20, area.h - 70);
96 void WRemoteConfig::draw()
100 drawText(tr("Command"), 15, 4, DrawStyle::LIGHTTEXT);
101 drawText(tr("Hard wired"), 165, 4, DrawStyle::LIGHTTEXT);
102 drawText(tr("User assignable"), 315, 4, DrawStyle::LIGHTTEXT);
106 drawText(tr("Learning! Press any hardwired key to exit."), 15, area.h - 30, DrawStyle::SELECTHIGHLIGHT);
110 drawText(tr("Press [ok] for learning or MENU to reset to defaults."), 15, area.h - 30, DrawStyle::LIGHTTEXT);
114 bool WRemoteConfig::mouseLBDOWN(int x, int y)
116 if (sl.mouseLBDOWN(x,y))
118 BoxStack::getInstance()->handleCommand(Input::OK); //simulate OK press
124 bool WRemoteConfig::mouseMove(int x, int y)
126 if (sl.mouseMove(x,y))
128 sl.setShowSelOption(true);
135 void WRemoteConfig::processMessage(Message* m)
137 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
139 if (m->message == Message::MOUSE_MOVE)
141 if (sl.mouseMove(m->parameter - getScreenX(), m->tag - getScreenY()))
143 sl.setShowSelOption(true);
145 viewman->updateView(this);
148 else if (m->message == Message::MOUSE_LBDOWN)
150 if (sl.mouseLBDOWN(m->parameter - getScreenX(), m->tag - getScreenY()))
152 ViewMan::getInstance()->handleCommand(Input::OK); //simulate OK press
156 //check if press is outside this view! then simulate cancel
157 int x = m->parameter - getScreenX();
158 int y = m->tag - getScreenY();
159 if (x<0 || y <0 || x>getWidth() || y>getHeight())
161 ViewMan::getInstance()->handleCommand(Input::BACK); //simulate cancel press
169 void WRemoteConfig::doSave()
171 Message* m = new Message();
172 m->message = Message::CHANGED_REMOTECONTROL;
175 //Control::getInstance()->postMessage(m);
180 int WRemoteConfig::handleCommand(int command)
185 if (command == Input::NA_LEARN)
187 initSelectList(false);
195 if (sl.getCurrentOption() != 0)
202 sl.setShowSelOption(false);
204 return 4; // return control to vopts
212 sl.setShowSelOption(true);
220 case Input::SKIPBACK:
225 case Input::SKIPFORWARD:
233 // Two casts to get from void* to UCHAR. Wow. First reinterpret from void* to ULONG, then static to UCHAR
234 InputMan::getInstance()->EnterLearningMode(
235 static_cast<UCHAR>(reinterpret_cast<ULONG>(sl.getCurrentOptionData())));
244 // Instead of returning 4 here which would delete this view
245 // before the doSave message is processed, let the message queue
246 // do the doSave then this close message. That will make the options menu
247 // disappear before this view
249 Message* m = new Message();
250 m->message = Message::CLOSE_ME;
253 //Control::getInstance()->postMessage(m);
259 InputMan::getInstance()->ResetToDefault();
260 initSelectList(false);