blob: 73aab03527bbe2a1e904635c30e10dd5aa0939e4 [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 Bocekfafb0c52013-07-25 22:53:02 +0200522 std::vector<ActionObject*>::iterator iter;
Dees_Troy51a0e822012-09-05 15:24:24 -0400523
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200524 // Don't try to handle a lack of handlers
525 if (mActions.size() == 0)
526 return 1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400527
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200528 for (iter = mActions.begin(); iter != mActions.end(); ++iter)
529 {
530 if ((*iter)->NotifyVarChange(varName, value))
531 LOGERR("An action handler errored on NotifyVarChange.\n");
532 }
533 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400534}
535
536PageSet::PageSet(char* xmlFile)
537{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200538 mResources = NULL;
539 mCurrentPage = NULL;
540 mOverlayPage = NULL;
Dees_Troy51a0e822012-09-05 15:24:24 -0400541
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200542 mXmlFile = xmlFile;
543 if (xmlFile)
544 mDoc.parse<0>(mXmlFile);
545 else
546 mCurrentPage = new Page(NULL);
Dees_Troy51a0e822012-09-05 15:24:24 -0400547}
548
549PageSet::~PageSet()
550{
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100551 for (std::vector<Page*>::iterator itr = mPages.begin(); itr != mPages.end(); ++itr)
552 delete *itr;
553
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200554 delete mResources;
555 free(mXmlFile);
Dees_Troy51a0e822012-09-05 15:24:24 -0400556}
557
558int PageSet::Load(ZipArchive* package)
559{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200560 xml_node<>* parent;
561 xml_node<>* child;
562 xml_node<>* templates;
Dees_Troy51a0e822012-09-05 15:24:24 -0400563
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200564 parent = mDoc.first_node("recovery");
565 if (!parent)
566 parent = mDoc.first_node("install");
Dees_Troy51a0e822012-09-05 15:24:24 -0400567
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200568 // Now, let's parse the XML
569 LOGINFO("Loading resources...\n");
570 child = parent->first_node("resources");
571 if (child)
572 mResources = new ResourceManager(child, package);
Dees_Troy51a0e822012-09-05 15:24:24 -0400573
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200574 LOGINFO("Loading variables...\n");
575 child = parent->first_node("variables");
576 if (child)
577 LoadVariables(child);
Dees_Troy51a0e822012-09-05 15:24:24 -0400578
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100579 LOGINFO("Loading mouse cursor...\n");
580 child = parent->first_node("mousecursor");
581 if(child)
582 PageManager::LoadCursorData(child);
583
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200584 LOGINFO("Loading pages...\n");
585 // This may be NULL if no templates are present
586 templates = parent->first_node("templates");
Dees_Troy51a0e822012-09-05 15:24:24 -0400587
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200588 child = parent->first_node("pages");
589 if (!child)
590 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400591
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200592 return LoadPages(child, templates);
Dees_Troy51a0e822012-09-05 15:24:24 -0400593}
594
595int PageSet::SetPage(std::string page)
596{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200597 Page* tmp = FindPage(page);
598 if (tmp)
599 {
600 if (mCurrentPage) mCurrentPage->SetPageFocus(0);
601 mCurrentPage = tmp;
602 mCurrentPage->SetPageFocus(1);
603 mCurrentPage->NotifyVarChange("", "");
604 return 0;
605 }
606 else
607 {
608 LOGERR("Unable to locate page (%s)\n", page.c_str());
609 }
610 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400611}
612
613int PageSet::SetOverlay(Page* page)
614{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200615 if (mOverlayPage) mOverlayPage->SetPageFocus(0);
616 mOverlayPage = page;
617 if (mOverlayPage)
618 {
619 mOverlayPage->SetPageFocus(1);
620 mOverlayPage->NotifyVarChange("", "");
621 }
622 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400623}
624
625Resource* PageSet::FindResource(std::string name)
626{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200627 return mResources ? mResources->FindResource(name) : NULL;
Dees_Troy51a0e822012-09-05 15:24:24 -0400628}
629
630Page* PageSet::FindPage(std::string name)
631{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200632 std::vector<Page*>::iterator iter;
Dees_Troy51a0e822012-09-05 15:24:24 -0400633
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200634 for (iter = mPages.begin(); iter != mPages.end(); iter++)
635 {
636 if (name == (*iter)->GetName())
637 return (*iter);
638 }
639 return NULL;
Dees_Troy51a0e822012-09-05 15:24:24 -0400640}
641
642int PageSet::LoadVariables(xml_node<>* vars)
643{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200644 xml_node<>* child;
Vojtech Bocek81c29dc2013-12-07 23:02:09 +0100645 xml_attribute<> *name, *value, *persist;
646 int p;
Dees_Troy51a0e822012-09-05 15:24:24 -0400647
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200648 child = vars->first_node("variable");
649 while (child)
650 {
Vojtech Bocek81c29dc2013-12-07 23:02:09 +0100651 name = child->first_attribute("name");
652 value = child->first_attribute("value");
653 persist = child->first_attribute("persist");
654 if(name && value)
655 {
656 p = persist ? atoi(persist->value()) : 0;
657 DataManager::SetValue(name->value(), value->value(), p);
658 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400659
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200660 child = child->next_sibling("variable");
661 }
662 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400663}
664
665int PageSet::LoadPages(xml_node<>* pages, xml_node<>* templates /* = NULL */)
666{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200667 xml_node<>* child;
Dees_Troy51a0e822012-09-05 15:24:24 -0400668
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200669 if (!pages)
670 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400671
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200672 child = pages->first_node("page");
673 while (child != NULL)
674 {
675 Page* page = new Page(child, templates);
676 if (page->GetName().empty())
677 {
678 LOGERR("Unable to process load page\n");
679 delete page;
680 }
681 else
682 {
683 mPages.push_back(page);
684 }
685 child = child->next_sibling("page");
686 }
687 if (mPages.size() > 0)
688 return 0;
689 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400690}
691
692int PageSet::IsCurrentPage(Page* page)
693{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200694 return ((mCurrentPage && mCurrentPage == page) ? 1 : 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400695}
696
697int PageSet::Render(void)
698{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200699 int ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400700
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200701 ret = (mCurrentPage ? mCurrentPage->Render() : -1);
702 if (ret < 0)
703 return ret;
704 ret = (mOverlayPage ? mOverlayPage->Render() : -1);
705 return ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400706}
707
708int PageSet::Update(void)
709{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200710 int ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400711
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200712 ret = (mCurrentPage ? mCurrentPage->Update() : -1);
713 if (ret < 0 || ret > 1)
714 return ret;
715 ret = (mOverlayPage ? mOverlayPage->Update() : -1);
716 return ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400717}
718
719int PageSet::NotifyTouch(TOUCH_STATE state, int x, int y)
720{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200721 if (mOverlayPage)
722 return (mOverlayPage->NotifyTouch(state, x, y));
723
724 return (mCurrentPage ? mCurrentPage->NotifyTouch(state, x, y) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -0400725}
726
727int PageSet::NotifyKey(int key)
728{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200729 if (mOverlayPage)
730 return (mOverlayPage->NotifyKey(key));
731
732 return (mCurrentPage ? mCurrentPage->NotifyKey(key) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -0400733}
734
735int PageSet::NotifyKeyboard(int key)
736{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200737 if (mOverlayPage)
738 return (mOverlayPage->NotifyKeyboard(key));
739
740 return (mCurrentPage ? mCurrentPage->NotifyKeyboard(key) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -0400741}
742
743int PageSet::SetKeyBoardFocus(int inFocus)
744{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200745 if (mOverlayPage)
746 return (mOverlayPage->SetKeyBoardFocus(inFocus));
747
748 return (mCurrentPage ? mCurrentPage->SetKeyBoardFocus(inFocus) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -0400749}
750
751int PageSet::NotifyVarChange(std::string varName, std::string value)
752{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200753 if (mOverlayPage)
754 mOverlayPage->NotifyVarChange(varName, value);
755
756 return (mCurrentPage ? mCurrentPage->NotifyVarChange(varName, value) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -0400757}
758
759int PageManager::LoadPackage(std::string name, std::string package, std::string startpage)
760{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200761 int fd;
762 ZipArchive zip, *pZip = NULL;
763 long len;
764 char* xmlFile = NULL;
765 PageSet* pageSet = NULL;
766 int ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400767
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200768 // Open the XML file
769 LOGINFO("Loading package: %s (%s)\n", name.c_str(), package.c_str());
770 if (mzOpenZipArchive(package.c_str(), &zip))
771 {
772 // We can try to load the XML directly...
773 struct stat st;
774 if(stat(package.c_str(),&st) != 0)
775 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400776
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200777 len = st.st_size;
778 xmlFile = (char*) malloc(len + 1);
779 if (!xmlFile)
780 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400781
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200782 fd = open(package.c_str(), O_RDONLY);
783 if (fd == -1)
784 goto error;
Dees_Troy51a0e822012-09-05 15:24:24 -0400785
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200786 read(fd, xmlFile, len);
787 close(fd);
788 }
789 else
790 {
791 pZip = &zip;
792 const ZipEntry* ui_xml = mzFindZipEntry(&zip, "ui.xml");
793 if (ui_xml == NULL)
794 {
795 LOGERR("Unable to locate ui.xml in zip file\n");
796 goto error;
797 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400798
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200799 // Allocate the buffer for the file
800 len = mzGetZipEntryUncompLen(ui_xml);
801 xmlFile = (char*) malloc(len + 1);
802 if (!xmlFile)
803 goto error;
804
805 if (!mzExtractZipEntryToBuffer(&zip, ui_xml, (unsigned char*) xmlFile))
806 {
807 LOGERR("Unable to extract ui.xml\n");
808 goto error;
809 }
810 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400811
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200812 // NULL-terminate the string
813 xmlFile[len] = 0x00;
Dees_Troy51a0e822012-09-05 15:24:24 -0400814
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200815 // Before loading, mCurrentSet must be the loading package so we can find resources
816 pageSet = mCurrentSet;
817 mCurrentSet = new PageSet(xmlFile);
818
819 ret = mCurrentSet->Load(pZip);
820 if (ret == 0)
821 {
822 mCurrentSet->SetPage(startpage);
823 mPageSets.insert(std::pair<std::string, PageSet*>(name, mCurrentSet));
824 }
825 else
826 {
827 LOGERR("Package %s failed to load.\n", name.c_str());
828 }
829
830 // The first successful package we loaded is the base
831 if (mBaseSet == NULL)
832 mBaseSet = mCurrentSet;
833
834 mCurrentSet = pageSet;
835
836 if (pZip)
837 mzCloseZipArchive(pZip);
838 return ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400839
840error:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200841 LOGERR("An internal error has occurred.\n");
842 if (pZip)
843 mzCloseZipArchive(pZip);
844 if (xmlFile)
845 free(xmlFile);
846 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400847}
848
849PageSet* PageManager::FindPackage(std::string name)
850{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200851 std::map<std::string, PageSet*>::iterator iter;
Dees_Troy51a0e822012-09-05 15:24:24 -0400852
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200853 iter = mPageSets.find(name);
854 if (iter != mPageSets.end())
855 return (*iter).second;
856
857 LOGERR("Unable to locate package %s\n", name.c_str());
858 return NULL;
Dees_Troy51a0e822012-09-05 15:24:24 -0400859}
860
861PageSet* PageManager::SelectPackage(std::string name)
862{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200863 LOGINFO("Switching packages (%s)\n", name.c_str());
864 PageSet* tmp;
Dees_Troy51a0e822012-09-05 15:24:24 -0400865
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200866 tmp = FindPackage(name);
867 if (tmp)
868 mCurrentSet = tmp;
869 else
870 LOGERR("Unable to find package.\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400871
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200872 return mCurrentSet;
Dees_Troy51a0e822012-09-05 15:24:24 -0400873}
874
875int PageManager::ReloadPackage(std::string name, std::string package)
876{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200877 std::map<std::string, PageSet*>::iterator iter;
Dees_Troy51a0e822012-09-05 15:24:24 -0400878
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200879 iter = mPageSets.find(name);
880 if (iter == mPageSets.end())
881 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400882
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100883 if(mMouseCursor)
884 mMouseCursor->ResetData(gr_fb_width(), gr_fb_height());
885
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200886 PageSet* set = (*iter).second;
887 mPageSets.erase(iter);
Dees_Troy51a0e822012-09-05 15:24:24 -0400888
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200889 if (LoadPackage(name, package, "main") != 0)
890 {
891 LOGERR("Failed to load package.\n");
892 mPageSets.insert(std::pair<std::string, PageSet*>(name, set));
893 return -1;
894 }
895 if (mCurrentSet == set)
896 SelectPackage(name);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100897 if (mBaseSet == set)
898 mBaseSet = mCurrentSet;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200899 delete set;
900 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400901}
902
903void PageManager::ReleasePackage(std::string name)
904{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200905 std::map<std::string, PageSet*>::iterator iter;
Dees_Troy51a0e822012-09-05 15:24:24 -0400906
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200907 iter = mPageSets.find(name);
908 if (iter == mPageSets.end())
909 return;
Dees_Troy51a0e822012-09-05 15:24:24 -0400910
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200911 PageSet* set = (*iter).second;
912 mPageSets.erase(iter);
913 delete set;
914 return;
Dees_Troy51a0e822012-09-05 15:24:24 -0400915}
916
917int PageManager::ChangePage(std::string name)
918{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200919 DataManager::SetValue("tw_operation_state", 0);
920 int ret = (mCurrentSet ? mCurrentSet->SetPage(name) : -1);
921 return ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400922}
923
924int PageManager::ChangeOverlay(std::string name)
925{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200926 if (name.empty())
927 return mCurrentSet->SetOverlay(NULL);
928 else
929 {
930 Page* page = mBaseSet ? mBaseSet->FindPage(name) : NULL;
931 return mCurrentSet->SetOverlay(page);
932 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400933}
934
935Resource* PageManager::FindResource(std::string name)
936{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200937 return (mCurrentSet ? mCurrentSet->FindResource(name) : NULL);
Dees_Troy51a0e822012-09-05 15:24:24 -0400938}
939
940Resource* PageManager::FindResource(std::string package, std::string name)
941{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200942 PageSet* tmp;
Dees_Troy51a0e822012-09-05 15:24:24 -0400943
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200944 tmp = FindPackage(name);
945 return (tmp ? tmp->FindResource(name) : NULL);
Dees_Troy51a0e822012-09-05 15:24:24 -0400946}
947
948int PageManager::SwitchToConsole(void)
949{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200950 PageSet* console = new PageSet(NULL);
Dees_Troy51a0e822012-09-05 15:24:24 -0400951
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200952 mCurrentSet = console;
953 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400954}
955
956int PageManager::IsCurrentPage(Page* page)
957{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200958 return (mCurrentSet ? mCurrentSet->IsCurrentPage(page) : 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400959}
960
961int PageManager::Render(void)
962{
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100963 int res = (mCurrentSet ? mCurrentSet->Render() : -1);
964 if(mMouseCursor)
965 mMouseCursor->Render();
966 return res;
967}
968
969MouseCursor *PageManager::GetMouseCursor()
970{
971 if(!mMouseCursor)
972 mMouseCursor = new MouseCursor(gr_fb_width(), gr_fb_height());
973 return mMouseCursor;
974}
975
976void PageManager::LoadCursorData(xml_node<>* node)
977{
978 if(!mMouseCursor)
979 mMouseCursor = new MouseCursor(gr_fb_width(), gr_fb_height());
980
981 mMouseCursor->LoadData(node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400982}
983
984int PageManager::Update(void)
985{
Ricardo Gomezc9ecd442013-07-05 16:13:52 -0700986#ifndef TW_NO_SCREEN_TIMEOUT
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200987 if(blankTimer.IsScreenOff())
988 return 0;
Ricardo Gomezc9ecd442013-07-05 16:13:52 -0700989#endif
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100990
991 int res = (mCurrentSet ? mCurrentSet->Update() : -1);
992
993 if(mMouseCursor)
994 {
995 int c_res = mMouseCursor->Update();
996 if(c_res > res)
997 res = c_res;
998 }
999 return res;
Dees_Troy51a0e822012-09-05 15:24:24 -04001000}
1001
1002int PageManager::NotifyTouch(TOUCH_STATE state, int x, int y)
1003{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001004 return (mCurrentSet ? mCurrentSet->NotifyTouch(state, x, y) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001005}
1006
1007int PageManager::NotifyKey(int key)
1008{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001009 return (mCurrentSet ? mCurrentSet->NotifyKey(key) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001010}
1011
1012int PageManager::NotifyKeyboard(int key)
1013{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001014 return (mCurrentSet ? mCurrentSet->NotifyKeyboard(key) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001015}
1016
1017int PageManager::SetKeyBoardFocus(int inFocus)
1018{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001019 return (mCurrentSet ? mCurrentSet->SetKeyBoardFocus(inFocus) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001020}
1021
1022int PageManager::NotifyVarChange(std::string varName, std::string value)
1023{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001024 return (mCurrentSet ? mCurrentSet->NotifyVarChange(varName, value) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001025}
1026
1027extern "C" void gui_notifyVarChange(const char *name, const char* value)
1028{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001029 if (!gGuiRunning)
1030 return;
Dees_Troy51a0e822012-09-05 15:24:24 -04001031
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001032 PageManager::NotifyVarChange(name, value);
Dees_Troy51a0e822012-09-05 15:24:24 -04001033}