blob: 2953eddb8a9541a07154d5ba60d031bcafae7637 [file] [log] [blame]
Dees_Troya13d74f2013-03-24 08:54:55 -05001/*
2 Copyright 2013 bigbiff/Dees_Troy TeamWin
3 This file is part of TWRP/TeamWin Recovery Project.
4
5 TWRP is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 TWRP is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with TWRP. If not, see <http://www.gnu.org/licenses/>.
17*/
Dees Troy3be70a82013-10-22 14:25:12 +000018
Dees_Troya13d74f2013-03-24 08:54:55 -050019// pages.cpp - Source to manage GUI base objects
Dees_Troy51a0e822012-09-05 15:24:24 -040020
21#include <stdarg.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include <fcntl.h>
26#include <sys/reboot.h>
27#include <sys/stat.h>
28#include <sys/time.h>
29#include <sys/mman.h>
30#include <sys/types.h>
31#include <sys/ioctl.h>
32#include <time.h>
33#include <unistd.h>
34#include <stdlib.h>
35
36#include <string>
37
38extern "C" {
Dees_Troy2673cec2013-04-02 20:22:16 +000039#include "../twcommon.h"
Dees_Troy51a0e822012-09-05 15:24:24 -040040#include "../minuitwrp/minui.h"
Dees_Troy51a0e822012-09-05 15:24:24 -040041}
42
43#include "rapidxml.hpp"
44#include "objects.hpp"
Ricardo Gomezc9ecd442013-07-05 16:13:52 -070045#ifndef TW_NO_SCREEN_TIMEOUT
gordon13370d9133d2013-06-08 14:17:07 +020046#include "blanktimer.hpp"
Ricardo Gomezc9ecd442013-07-05 16:13:52 -070047#endif
Dees_Troy51a0e822012-09-05 15:24:24 -040048
49extern int gGuiRunning;
Ricardo Gomezc9ecd442013-07-05 16:13:52 -070050#ifndef TW_NO_SCREEN_TIMEOUT
gordon13370d9133d2013-06-08 14:17:07 +020051extern blanktimer blankTimer;
Ricardo Gomezc9ecd442013-07-05 16:13:52 -070052#endif
Dees_Troy51a0e822012-09-05 15:24:24 -040053
54std::map<std::string, PageSet*> PageManager::mPageSets;
55PageSet* PageManager::mCurrentSet;
56PageSet* PageManager::mBaseSet = NULL;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010057MouseCursor *PageManager::mMouseCursor = NULL;
Dees_Troy51a0e822012-09-05 15:24:24 -040058
Dees_Troy51a0e822012-09-05 15:24:24 -040059// Helper routine to convert a string to a color declaration
60int ConvertStrToColor(std::string str, COLOR* color)
61{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020062 // Set the default, solid black
63 memset(color, 0, sizeof(COLOR));
64 color->alpha = 255;
Dees_Troy51a0e822012-09-05 15:24:24 -040065
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020066 // Translate variables
67 DataManager::GetValue(str, str);
68
69 // Look for some defaults
70 if (str == "black") return 0;
71 else if (str == "white") { color->red = color->green = color->blue = 255; return 0; }
72 else if (str == "red") { color->red = 255; return 0; }
73 else if (str == "green") { color->green = 255; return 0; }
74 else if (str == "blue") { color->blue = 255; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040075
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020076 // At this point, we require an RGB(A) color
77 if (str[0] != '#')
78 return -1;
79
80 str.erase(0, 1);
Dees_Troy51a0e822012-09-05 15:24:24 -040081
Dees_Troy30b962e2012-10-19 20:48:59 -040082 int result;
83 if (str.size() >= 8) {
84 // We have alpha channel
85 string alpha = str.substr(6, 2);
86 result = strtol(alpha.c_str(), NULL, 16);
87 color->alpha = result & 0x000000FF;
88 str.resize(6);
89 result = strtol(str.c_str(), NULL, 16);
90 color->red = (result >> 16) & 0x000000FF;
91 color->green = (result >> 8) & 0x000000FF;
92 color->blue = result & 0x000000FF;
93 } else {
94 result = strtol(str.c_str(), NULL, 16);
95 color->red = (result >> 16) & 0x000000FF;
96 color->green = (result >> 8) & 0x000000FF;
97 color->blue = result & 0x000000FF;
98 }
99 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400100}
101
102// Helper APIs
103bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w /* = NULL */, int* h /* = NULL */, RenderObject::Placement* placement /* = NULL */)
104{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200105 if (!node)
106 return false;
Dees_Troy51a0e822012-09-05 15:24:24 -0400107
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200108 std::string value;
109 if (node->first_attribute("x"))
110 {
111 value = node->first_attribute("x")->value();
112 DataManager::GetValue(value, value);
113 *x = atol(value.c_str());
114 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400115
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200116 if (node->first_attribute("y"))
117 {
118 value = node->first_attribute("y")->value();
119 DataManager::GetValue(value, value);
120 *y = atol(value.c_str());
121 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400122
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200123 if (w && node->first_attribute("w"))
124 {
125 value = node->first_attribute("w")->value();
126 DataManager::GetValue(value, value);
127 *w = atol(value.c_str());
128 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400129
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200130 if (h && node->first_attribute("h"))
131 {
132 value = node->first_attribute("h")->value();
133 DataManager::GetValue(value, value);
134 *h = atol(value.c_str());
135 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400136
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200137 if (placement && node->first_attribute("placement"))
138 {
139 value = node->first_attribute("placement")->value();
140 DataManager::GetValue(value, value);
141 *placement = (RenderObject::Placement) atol(value.c_str());
142 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400143
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200144 return true;
Dees_Troy51a0e822012-09-05 15:24:24 -0400145}
146
147int ActionObject::SetActionPos(int x, int y, int w, int h)
148{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200149 if (x < 0 || y < 0)
150 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400151
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200152 mActionX = x;
153 mActionY = y;
154 if (w || h)
155 {
156 mActionW = w;
157 mActionH = h;
158 }
159 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400160}
161
162Page::Page(xml_node<>* page, xml_node<>* templates /* = NULL */)
163{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200164 mTouchStart = NULL;
Dees_Troy51a0e822012-09-05 15:24:24 -0400165
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200166 // We can memset the whole structure, because the alpha channel is ignored
167 memset(&mBackground, 0, sizeof(COLOR));
Dees_Troy51a0e822012-09-05 15:24:24 -0400168
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200169 // With NULL, we make a console-only display
170 if (!page)
171 {
172 mName = "console";
Dees_Troy51a0e822012-09-05 15:24:24 -0400173
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200174 GUIConsole* element = new GUIConsole(NULL);
175 mRenders.push_back(element);
176 mActions.push_back(element);
177 return;
178 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400179
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200180 if (page->first_attribute("name"))
181 mName = page->first_attribute("name")->value();
182 else
183 {
184 LOGERR("No page name attribute found!\n");
185 return;
186 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400187
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200188 LOGINFO("Loading page %s\n", mName.c_str());
Dees_Troy51a0e822012-09-05 15:24:24 -0400189
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200190 // This is a recursive routine for template handling
191 ProcessNode(page, templates);
Dees_Troy51a0e822012-09-05 15:24:24 -0400192
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200193 return;
Dees_Troy51a0e822012-09-05 15:24:24 -0400194}
195
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100196Page::~Page()
197{
198 for (std::vector<GUIObject*>::iterator itr = mObjects.begin(); itr != mObjects.end(); ++itr)
199 delete *itr;
200}
201
Dees_Troy51a0e822012-09-05 15:24:24 -0400202bool Page::ProcessNode(xml_node<>* page, xml_node<>* templates /* = NULL */, int depth /* = 0 */)
203{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200204 if (depth == 10)
205 {
206 LOGERR("Page processing depth has exceeded 10. Failing out. This is likely a recursive template.\n");
207 return false;
208 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400209
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200210 // Let's retrieve the background value, if any
211 xml_node<>* bg = page->first_node("background");
212 if (bg)
213 {
214 xml_attribute<>* attr = bg->first_attribute("color");
215 if (attr)
216 {
217 std::string color = attr->value();
218 ConvertStrToColor(color, &mBackground);
219 }
220 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400221
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200222 xml_node<>* child;
223 child = page->first_node("object");
224 while (child)
225 {
226 if (!child->first_attribute("type"))
227 break;
Dees_Troy51a0e822012-09-05 15:24:24 -0400228
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200229 std::string type = child->first_attribute("type")->value();
Dees_Troy51a0e822012-09-05 15:24:24 -0400230
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200231 if (type == "text")
232 {
233 GUIText* element = new GUIText(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100234 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200235 mRenders.push_back(element);
236 mActions.push_back(element);
237 }
238 else if (type == "image")
239 {
240 GUIImage* element = new GUIImage(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100241 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200242 mRenders.push_back(element);
243 }
244 else if (type == "fill")
245 {
246 GUIFill* element = new GUIFill(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100247 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200248 mRenders.push_back(element);
249 }
250 else if (type == "action")
251 {
252 GUIAction* element = new GUIAction(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100253 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200254 mActions.push_back(element);
255 }
256 else if (type == "console")
257 {
258 GUIConsole* element = new GUIConsole(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100259 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200260 mRenders.push_back(element);
261 mActions.push_back(element);
262 }
263 else if (type == "button")
264 {
265 GUIButton* element = new GUIButton(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100266 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200267 mRenders.push_back(element);
268 mActions.push_back(element);
269 }
270 else if (type == "checkbox")
271 {
272 GUICheckbox* element = new GUICheckbox(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100273 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200274 mRenders.push_back(element);
275 mActions.push_back(element);
276 }
277 else if (type == "fileselector")
278 {
279 GUIFileSelector* element = new GUIFileSelector(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100280 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200281 mRenders.push_back(element);
282 mActions.push_back(element);
283 }
284 else if (type == "animation")
285 {
286 GUIAnimation* element = new GUIAnimation(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100287 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200288 mRenders.push_back(element);
289 }
290 else if (type == "progressbar")
291 {
292 GUIProgressBar* element = new GUIProgressBar(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100293 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200294 mRenders.push_back(element);
295 mActions.push_back(element);
296 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400297 else if (type == "slider")
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200298 {
299 GUISlider* element = new GUISlider(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100300 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200301 mRenders.push_back(element);
302 mActions.push_back(element);
303 }
Vojtech Bocek85932342013-04-01 22:11:33 +0200304 else if (type == "slidervalue")
305 {
306 GUISliderValue *element = new GUISliderValue(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100307 mObjects.push_back(element);
Vojtech Bocek85932342013-04-01 22:11:33 +0200308 mRenders.push_back(element);
309 mActions.push_back(element);
310 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400311 else if (type == "listbox")
312 {
313 GUIListBox* element = new GUIListBox(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100314 mObjects.push_back(element);
Dees_Troy51a0e822012-09-05 15:24:24 -0400315 mRenders.push_back(element);
316 mActions.push_back(element);
317 }
318 else if (type == "keyboard")
319 {
320 GUIKeyboard* element = new GUIKeyboard(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100321 mObjects.push_back(element);
Dees_Troy51a0e822012-09-05 15:24:24 -0400322 mRenders.push_back(element);
323 mActions.push_back(element);
324 }
325 else if (type == "input")
326 {
327 GUIInput* element = new GUIInput(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100328 mObjects.push_back(element);
Dees_Troy51a0e822012-09-05 15:24:24 -0400329 mRenders.push_back(element);
330 mActions.push_back(element);
331 mInputs.push_back(element);
332 }
Dees_Troya13d74f2013-03-24 08:54:55 -0500333 else if (type == "partitionlist")
334 {
335 GUIPartitionList* element = new GUIPartitionList(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100336 mObjects.push_back(element);
Dees_Troya13d74f2013-03-24 08:54:55 -0500337 mRenders.push_back(element);
338 mActions.push_back(element);
339 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200340 else if (type == "template")
341 {
342 if (!templates || !child->first_attribute("name"))
343 {
344 LOGERR("Invalid template request.\n");
345 }
346 else
347 {
348 std::string name = child->first_attribute("name")->value();
Dees_Troy51a0e822012-09-05 15:24:24 -0400349
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200350 // We need to find the correct template
351 xml_node<>* node;
352 node = templates->first_node("template");
Dees_Troy51a0e822012-09-05 15:24:24 -0400353
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200354 while (node)
355 {
356 if (!node->first_attribute("name"))
357 continue;
Dees_Troy51a0e822012-09-05 15:24:24 -0400358
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200359 if (name == node->first_attribute("name")->value())
360 {
361 if (!ProcessNode(node, templates, depth + 1))
362 return false;
363 else
364 break;
365 }
366 node = node->next_sibling("template");
367 }
368 }
369 }
370 else
371 {
372 LOGERR("Unknown object type.\n");
373 }
374 child = child->next_sibling("object");
375 }
376 return true;
Dees_Troy51a0e822012-09-05 15:24:24 -0400377}
378
379int Page::Render(void)
380{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200381 // Render background
382 gr_color(mBackground.red, mBackground.green, mBackground.blue, mBackground.alpha);
383 gr_fill(0, 0, gr_fb_width(), gr_fb_height());
Dees_Troy51a0e822012-09-05 15:24:24 -0400384
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200385 // Render remaining objects
386 std::vector<RenderObject*>::iterator iter;
387 for (iter = mRenders.begin(); iter != mRenders.end(); iter++)
388 {
389 if ((*iter)->Render())
390 LOGERR("A render request has failed.\n");
391 }
392 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400393}
394
395int Page::Update(void)
396{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200397 int retCode = 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400398
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200399 std::vector<RenderObject*>::iterator iter;
400 for (iter = mRenders.begin(); iter != mRenders.end(); iter++)
401 {
402 int ret = (*iter)->Update();
403 if (ret < 0)
404 LOGERR("An update request has failed.\n");
405 else if (ret > retCode)
406 retCode = ret;
407 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400408
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200409 return retCode;
Dees_Troy51a0e822012-09-05 15:24:24 -0400410}
411
412int Page::NotifyTouch(TOUCH_STATE state, int x, int y)
413{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200414 // By default, return 1 to ignore further touches if nobody is listening
415 int ret = 1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400416
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200417 // Don't try to handle a lack of handlers
418 if (mActions.size() == 0)
419 return ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400420
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200421 // We record mTouchStart so we can pass all the touch stream to the same handler
422 if (state == TOUCH_START)
423 {
424 std::vector<ActionObject*>::reverse_iterator iter;
425 // We work backwards, from top-most element to bottom-most element
426 for (iter = mActions.rbegin(); iter != mActions.rend(); iter++)
427 {
428 if ((*iter)->IsInRegion(x, y))
429 {
430 mTouchStart = (*iter);
431 ret = mTouchStart->NotifyTouch(state, x, y);
432 if (ret >= 0)
433 break;
434 mTouchStart = NULL;
435 }
436 }
437 }
438 else if (state == TOUCH_RELEASE && mTouchStart != NULL)
439 {
440 ret = mTouchStart->NotifyTouch(state, x, y);
441 mTouchStart = NULL;
442 }
443 else if ((state == TOUCH_DRAG || state == TOUCH_HOLD || state == TOUCH_REPEAT) && mTouchStart != NULL)
444 {
445 ret = mTouchStart->NotifyTouch(state, x, y);
446 }
447 return ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400448}
449
450int Page::NotifyKey(int key)
451{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200452 std::vector<ActionObject*>::reverse_iterator iter;
Dees_Troy51a0e822012-09-05 15:24:24 -0400453
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200454 // Don't try to handle a lack of handlers
455 if (mActions.size() == 0)
456 return 1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400457
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200458 // We work backwards, from top-most element to bottom-most element
459 for (iter = mActions.rbegin(); iter != mActions.rend(); iter++)
460 {
461 int ret = (*iter)->NotifyKey(key);
462 if (ret == 0)
463 return 0;
464 else if (ret < 0)
465 LOGERR("An action handler has returned an error");
466 }
467 return 1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400468}
469
470int Page::NotifyKeyboard(int key)
471{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200472 std::vector<InputObject*>::reverse_iterator iter;
Dees_Troy51a0e822012-09-05 15:24:24 -0400473
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200474 // Don't try to handle a lack of handlers
475 if (mInputs.size() == 0)
476 return 1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400477
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200478 // We work backwards, from top-most element to bottom-most element
479 for (iter = mInputs.rbegin(); iter != mInputs.rend(); iter++)
480 {
481 int ret = (*iter)->NotifyKeyboard(key);
482 if (ret == 0)
483 return 0;
484 else if (ret < 0)
485 LOGERR("A keyboard handler has returned an error");
486 }
487 return 1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400488}
489
490int Page::SetKeyBoardFocus(int inFocus)
491{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200492 std::vector<InputObject*>::reverse_iterator iter;
Dees_Troy51a0e822012-09-05 15:24:24 -0400493
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200494 // Don't try to handle a lack of handlers
495 if (mInputs.size() == 0)
496 return 1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400497
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200498 // We work backwards, from top-most element to bottom-most element
499 for (iter = mInputs.rbegin(); iter != mInputs.rend(); iter++)
500 {
501 int ret = (*iter)->SetInputFocus(inFocus);
502 if (ret == 0)
503 return 0;
504 else if (ret < 0)
505 LOGERR("An input focus handler has returned an error");
506 }
507 return 1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400508}
509
510void Page::SetPageFocus(int inFocus)
511{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200512 // Render remaining objects
513 std::vector<RenderObject*>::iterator iter;
514 for (iter = mRenders.begin(); iter != mRenders.end(); iter++)
515 (*iter)->SetPageFocus(inFocus);
516
517 return;
Dees_Troy51a0e822012-09-05 15:24:24 -0400518}
519
520int Page::NotifyVarChange(std::string varName, std::string value)
521{
Vojtech Bocek07220562014-02-08 02:05:33 +0100522 std::vector<GUIObject*>::iterator iter;
523 for (iter = mObjects.begin(); iter != mObjects.end(); ++iter)
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200524 {
525 if ((*iter)->NotifyVarChange(varName, value))
526 LOGERR("An action handler errored on NotifyVarChange.\n");
527 }
528 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400529}
530
531PageSet::PageSet(char* xmlFile)
532{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200533 mResources = NULL;
534 mCurrentPage = NULL;
535 mOverlayPage = NULL;
Dees_Troy51a0e822012-09-05 15:24:24 -0400536
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200537 mXmlFile = xmlFile;
538 if (xmlFile)
539 mDoc.parse<0>(mXmlFile);
540 else
541 mCurrentPage = new Page(NULL);
Dees_Troy51a0e822012-09-05 15:24:24 -0400542}
543
544PageSet::~PageSet()
545{
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100546 for (std::vector<Page*>::iterator itr = mPages.begin(); itr != mPages.end(); ++itr)
547 delete *itr;
548
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200549 delete mResources;
550 free(mXmlFile);
Dees_Troy51a0e822012-09-05 15:24:24 -0400551}
552
553int PageSet::Load(ZipArchive* package)
554{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200555 xml_node<>* parent;
556 xml_node<>* child;
557 xml_node<>* templates;
Dees_Troy51a0e822012-09-05 15:24:24 -0400558
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200559 parent = mDoc.first_node("recovery");
560 if (!parent)
561 parent = mDoc.first_node("install");
Dees_Troy51a0e822012-09-05 15:24:24 -0400562
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200563 // Now, let's parse the XML
564 LOGINFO("Loading resources...\n");
565 child = parent->first_node("resources");
566 if (child)
567 mResources = new ResourceManager(child, package);
Dees_Troy51a0e822012-09-05 15:24:24 -0400568
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200569 LOGINFO("Loading variables...\n");
570 child = parent->first_node("variables");
571 if (child)
572 LoadVariables(child);
Dees_Troy51a0e822012-09-05 15:24:24 -0400573
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100574 LOGINFO("Loading mouse cursor...\n");
575 child = parent->first_node("mousecursor");
576 if(child)
577 PageManager::LoadCursorData(child);
578
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200579 LOGINFO("Loading pages...\n");
580 // This may be NULL if no templates are present
581 templates = parent->first_node("templates");
Dees_Troy51a0e822012-09-05 15:24:24 -0400582
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200583 child = parent->first_node("pages");
584 if (!child)
585 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400586
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200587 return LoadPages(child, templates);
Dees_Troy51a0e822012-09-05 15:24:24 -0400588}
589
590int PageSet::SetPage(std::string page)
591{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200592 Page* tmp = FindPage(page);
593 if (tmp)
594 {
595 if (mCurrentPage) mCurrentPage->SetPageFocus(0);
596 mCurrentPage = tmp;
597 mCurrentPage->SetPageFocus(1);
598 mCurrentPage->NotifyVarChange("", "");
599 return 0;
600 }
601 else
602 {
603 LOGERR("Unable to locate page (%s)\n", page.c_str());
604 }
605 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400606}
607
608int PageSet::SetOverlay(Page* page)
609{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200610 if (mOverlayPage) mOverlayPage->SetPageFocus(0);
611 mOverlayPage = page;
612 if (mOverlayPage)
613 {
614 mOverlayPage->SetPageFocus(1);
615 mOverlayPage->NotifyVarChange("", "");
616 }
617 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400618}
619
620Resource* PageSet::FindResource(std::string name)
621{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200622 return mResources ? mResources->FindResource(name) : NULL;
Dees_Troy51a0e822012-09-05 15:24:24 -0400623}
624
625Page* PageSet::FindPage(std::string name)
626{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200627 std::vector<Page*>::iterator iter;
Dees_Troy51a0e822012-09-05 15:24:24 -0400628
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200629 for (iter = mPages.begin(); iter != mPages.end(); iter++)
630 {
631 if (name == (*iter)->GetName())
632 return (*iter);
633 }
634 return NULL;
Dees_Troy51a0e822012-09-05 15:24:24 -0400635}
636
637int PageSet::LoadVariables(xml_node<>* vars)
638{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200639 xml_node<>* child;
Vojtech Bocek81c29dc2013-12-07 23:02:09 +0100640 xml_attribute<> *name, *value, *persist;
641 int p;
Dees_Troy51a0e822012-09-05 15:24:24 -0400642
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200643 child = vars->first_node("variable");
644 while (child)
645 {
Vojtech Bocek81c29dc2013-12-07 23:02:09 +0100646 name = child->first_attribute("name");
647 value = child->first_attribute("value");
648 persist = child->first_attribute("persist");
649 if(name && value)
650 {
651 p = persist ? atoi(persist->value()) : 0;
652 DataManager::SetValue(name->value(), value->value(), p);
653 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400654
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200655 child = child->next_sibling("variable");
656 }
657 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400658}
659
660int PageSet::LoadPages(xml_node<>* pages, xml_node<>* templates /* = NULL */)
661{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200662 xml_node<>* child;
Dees_Troy51a0e822012-09-05 15:24:24 -0400663
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200664 if (!pages)
665 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400666
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200667 child = pages->first_node("page");
668 while (child != NULL)
669 {
670 Page* page = new Page(child, templates);
671 if (page->GetName().empty())
672 {
673 LOGERR("Unable to process load page\n");
674 delete page;
675 }
676 else
677 {
678 mPages.push_back(page);
679 }
680 child = child->next_sibling("page");
681 }
682 if (mPages.size() > 0)
683 return 0;
684 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400685}
686
687int PageSet::IsCurrentPage(Page* page)
688{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200689 return ((mCurrentPage && mCurrentPage == page) ? 1 : 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400690}
691
692int PageSet::Render(void)
693{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200694 int ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400695
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200696 ret = (mCurrentPage ? mCurrentPage->Render() : -1);
697 if (ret < 0)
698 return ret;
699 ret = (mOverlayPage ? mOverlayPage->Render() : -1);
700 return ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400701}
702
703int PageSet::Update(void)
704{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200705 int ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400706
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200707 ret = (mCurrentPage ? mCurrentPage->Update() : -1);
708 if (ret < 0 || ret > 1)
709 return ret;
710 ret = (mOverlayPage ? mOverlayPage->Update() : -1);
711 return ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400712}
713
714int PageSet::NotifyTouch(TOUCH_STATE state, int x, int y)
715{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200716 if (mOverlayPage)
717 return (mOverlayPage->NotifyTouch(state, x, y));
718
719 return (mCurrentPage ? mCurrentPage->NotifyTouch(state, x, y) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -0400720}
721
722int PageSet::NotifyKey(int key)
723{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200724 if (mOverlayPage)
725 return (mOverlayPage->NotifyKey(key));
726
727 return (mCurrentPage ? mCurrentPage->NotifyKey(key) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -0400728}
729
730int PageSet::NotifyKeyboard(int key)
731{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200732 if (mOverlayPage)
733 return (mOverlayPage->NotifyKeyboard(key));
734
735 return (mCurrentPage ? mCurrentPage->NotifyKeyboard(key) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -0400736}
737
738int PageSet::SetKeyBoardFocus(int inFocus)
739{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200740 if (mOverlayPage)
741 return (mOverlayPage->SetKeyBoardFocus(inFocus));
742
743 return (mCurrentPage ? mCurrentPage->SetKeyBoardFocus(inFocus) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -0400744}
745
746int PageSet::NotifyVarChange(std::string varName, std::string value)
747{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200748 if (mOverlayPage)
749 mOverlayPage->NotifyVarChange(varName, value);
750
751 return (mCurrentPage ? mCurrentPage->NotifyVarChange(varName, value) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -0400752}
753
754int PageManager::LoadPackage(std::string name, std::string package, std::string startpage)
755{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200756 int fd;
757 ZipArchive zip, *pZip = NULL;
758 long len;
759 char* xmlFile = NULL;
760 PageSet* pageSet = NULL;
761 int ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400762
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200763 // Open the XML file
764 LOGINFO("Loading package: %s (%s)\n", name.c_str(), package.c_str());
765 if (mzOpenZipArchive(package.c_str(), &zip))
766 {
767 // We can try to load the XML directly...
768 struct stat st;
769 if(stat(package.c_str(),&st) != 0)
770 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400771
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200772 len = st.st_size;
773 xmlFile = (char*) malloc(len + 1);
774 if (!xmlFile)
775 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400776
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200777 fd = open(package.c_str(), O_RDONLY);
778 if (fd == -1)
779 goto error;
Dees_Troy51a0e822012-09-05 15:24:24 -0400780
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200781 read(fd, xmlFile, len);
782 close(fd);
783 }
784 else
785 {
786 pZip = &zip;
787 const ZipEntry* ui_xml = mzFindZipEntry(&zip, "ui.xml");
788 if (ui_xml == NULL)
789 {
790 LOGERR("Unable to locate ui.xml in zip file\n");
791 goto error;
792 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400793
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200794 // Allocate the buffer for the file
795 len = mzGetZipEntryUncompLen(ui_xml);
796 xmlFile = (char*) malloc(len + 1);
797 if (!xmlFile)
798 goto error;
799
800 if (!mzExtractZipEntryToBuffer(&zip, ui_xml, (unsigned char*) xmlFile))
801 {
802 LOGERR("Unable to extract ui.xml\n");
803 goto error;
804 }
805 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400806
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200807 // NULL-terminate the string
808 xmlFile[len] = 0x00;
Dees_Troy51a0e822012-09-05 15:24:24 -0400809
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200810 // Before loading, mCurrentSet must be the loading package so we can find resources
811 pageSet = mCurrentSet;
812 mCurrentSet = new PageSet(xmlFile);
813
814 ret = mCurrentSet->Load(pZip);
815 if (ret == 0)
816 {
817 mCurrentSet->SetPage(startpage);
818 mPageSets.insert(std::pair<std::string, PageSet*>(name, mCurrentSet));
819 }
820 else
821 {
822 LOGERR("Package %s failed to load.\n", name.c_str());
823 }
824
825 // The first successful package we loaded is the base
826 if (mBaseSet == NULL)
827 mBaseSet = mCurrentSet;
828
829 mCurrentSet = pageSet;
830
831 if (pZip)
832 mzCloseZipArchive(pZip);
833 return ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400834
835error:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200836 LOGERR("An internal error has occurred.\n");
837 if (pZip)
838 mzCloseZipArchive(pZip);
839 if (xmlFile)
840 free(xmlFile);
841 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400842}
843
844PageSet* PageManager::FindPackage(std::string name)
845{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200846 std::map<std::string, PageSet*>::iterator iter;
Dees_Troy51a0e822012-09-05 15:24:24 -0400847
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200848 iter = mPageSets.find(name);
849 if (iter != mPageSets.end())
850 return (*iter).second;
851
852 LOGERR("Unable to locate package %s\n", name.c_str());
853 return NULL;
Dees_Troy51a0e822012-09-05 15:24:24 -0400854}
855
856PageSet* PageManager::SelectPackage(std::string name)
857{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200858 LOGINFO("Switching packages (%s)\n", name.c_str());
859 PageSet* tmp;
Dees_Troy51a0e822012-09-05 15:24:24 -0400860
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200861 tmp = FindPackage(name);
862 if (tmp)
Vojtech Bocek07220562014-02-08 02:05:33 +0100863 {
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200864 mCurrentSet = tmp;
Vojtech Bocek07220562014-02-08 02:05:33 +0100865 mCurrentSet->NotifyVarChange("", "");
866 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200867 else
868 LOGERR("Unable to find package.\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400869
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200870 return mCurrentSet;
Dees_Troy51a0e822012-09-05 15:24:24 -0400871}
872
873int PageManager::ReloadPackage(std::string name, std::string package)
874{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200875 std::map<std::string, PageSet*>::iterator iter;
Dees_Troy51a0e822012-09-05 15:24:24 -0400876
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200877 iter = mPageSets.find(name);
878 if (iter == mPageSets.end())
879 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400880
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100881 if(mMouseCursor)
882 mMouseCursor->ResetData(gr_fb_width(), gr_fb_height());
883
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200884 PageSet* set = (*iter).second;
885 mPageSets.erase(iter);
Dees_Troy51a0e822012-09-05 15:24:24 -0400886
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200887 if (LoadPackage(name, package, "main") != 0)
888 {
889 LOGERR("Failed to load package.\n");
890 mPageSets.insert(std::pair<std::string, PageSet*>(name, set));
891 return -1;
892 }
893 if (mCurrentSet == set)
894 SelectPackage(name);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100895 if (mBaseSet == set)
896 mBaseSet = mCurrentSet;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200897 delete set;
898 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400899}
900
901void PageManager::ReleasePackage(std::string name)
902{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200903 std::map<std::string, PageSet*>::iterator iter;
Dees_Troy51a0e822012-09-05 15:24:24 -0400904
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200905 iter = mPageSets.find(name);
906 if (iter == mPageSets.end())
907 return;
Dees_Troy51a0e822012-09-05 15:24:24 -0400908
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200909 PageSet* set = (*iter).second;
910 mPageSets.erase(iter);
911 delete set;
912 return;
Dees_Troy51a0e822012-09-05 15:24:24 -0400913}
914
915int PageManager::ChangePage(std::string name)
916{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200917 DataManager::SetValue("tw_operation_state", 0);
918 int ret = (mCurrentSet ? mCurrentSet->SetPage(name) : -1);
919 return ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400920}
921
922int PageManager::ChangeOverlay(std::string name)
923{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200924 if (name.empty())
925 return mCurrentSet->SetOverlay(NULL);
926 else
927 {
928 Page* page = mBaseSet ? mBaseSet->FindPage(name) : NULL;
929 return mCurrentSet->SetOverlay(page);
930 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400931}
932
933Resource* PageManager::FindResource(std::string name)
934{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200935 return (mCurrentSet ? mCurrentSet->FindResource(name) : NULL);
Dees_Troy51a0e822012-09-05 15:24:24 -0400936}
937
938Resource* PageManager::FindResource(std::string package, std::string name)
939{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200940 PageSet* tmp;
Dees_Troy51a0e822012-09-05 15:24:24 -0400941
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200942 tmp = FindPackage(name);
943 return (tmp ? tmp->FindResource(name) : NULL);
Dees_Troy51a0e822012-09-05 15:24:24 -0400944}
945
946int PageManager::SwitchToConsole(void)
947{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200948 PageSet* console = new PageSet(NULL);
Dees_Troy51a0e822012-09-05 15:24:24 -0400949
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200950 mCurrentSet = console;
951 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400952}
953
954int PageManager::IsCurrentPage(Page* page)
955{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200956 return (mCurrentSet ? mCurrentSet->IsCurrentPage(page) : 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400957}
958
959int PageManager::Render(void)
960{
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100961 int res = (mCurrentSet ? mCurrentSet->Render() : -1);
962 if(mMouseCursor)
963 mMouseCursor->Render();
964 return res;
965}
966
967MouseCursor *PageManager::GetMouseCursor()
968{
969 if(!mMouseCursor)
970 mMouseCursor = new MouseCursor(gr_fb_width(), gr_fb_height());
971 return mMouseCursor;
972}
973
974void PageManager::LoadCursorData(xml_node<>* node)
975{
976 if(!mMouseCursor)
977 mMouseCursor = new MouseCursor(gr_fb_width(), gr_fb_height());
978
979 mMouseCursor->LoadData(node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400980}
981
982int PageManager::Update(void)
983{
Ricardo Gomezc9ecd442013-07-05 16:13:52 -0700984#ifndef TW_NO_SCREEN_TIMEOUT
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200985 if(blankTimer.IsScreenOff())
986 return 0;
Ricardo Gomezc9ecd442013-07-05 16:13:52 -0700987#endif
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100988
989 int res = (mCurrentSet ? mCurrentSet->Update() : -1);
990
991 if(mMouseCursor)
992 {
993 int c_res = mMouseCursor->Update();
994 if(c_res > res)
995 res = c_res;
996 }
997 return res;
Dees_Troy51a0e822012-09-05 15:24:24 -0400998}
999
1000int PageManager::NotifyTouch(TOUCH_STATE state, int x, int y)
1001{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001002 return (mCurrentSet ? mCurrentSet->NotifyTouch(state, x, y) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001003}
1004
1005int PageManager::NotifyKey(int key)
1006{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001007 return (mCurrentSet ? mCurrentSet->NotifyKey(key) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001008}
1009
1010int PageManager::NotifyKeyboard(int key)
1011{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001012 return (mCurrentSet ? mCurrentSet->NotifyKeyboard(key) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001013}
1014
1015int PageManager::SetKeyBoardFocus(int inFocus)
1016{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001017 return (mCurrentSet ? mCurrentSet->SetKeyBoardFocus(inFocus) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001018}
1019
1020int PageManager::NotifyVarChange(std::string varName, std::string value)
1021{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001022 return (mCurrentSet ? mCurrentSet->NotifyVarChange(varName, value) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001023}
1024
1025extern "C" void gui_notifyVarChange(const char *name, const char* value)
1026{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001027 if (!gGuiRunning)
1028 return;
Dees_Troy51a0e822012-09-05 15:24:24 -04001029
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001030 PageManager::NotifyVarChange(name, value);
Dees_Troy51a0e822012-09-05 15:24:24 -04001031}