blob: 4c98a7233712527239459d1ae7e53253eb2236b3 [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>
Ethan Yonkera2dc2f22014-11-08 08:13:40 -060035#include "../twrp-functions.hpp"
Dees_Troy51a0e822012-09-05 15:24:24 -040036
37#include <string>
38
39extern "C" {
Dees_Troy2673cec2013-04-02 20:22:16 +000040#include "../twcommon.h"
Dees_Troy51a0e822012-09-05 15:24:24 -040041#include "../minuitwrp/minui.h"
Ethan Yonkera2dc2f22014-11-08 08:13:40 -060042#include "../minzip/SysUtil.h"
43#include "../minzip/Zip.h"
Ethan Yonker63e414f2015-02-06 15:44:39 -060044#include "gui.h"
Dees_Troy51a0e822012-09-05 15:24:24 -040045}
46
47#include "rapidxml.hpp"
48#include "objects.hpp"
gordon13370d9133d2013-06-08 14:17:07 +020049#include "blanktimer.hpp"
Dees_Troy51a0e822012-09-05 15:24:24 -040050
51extern int gGuiRunning;
52
53std::map<std::string, PageSet*> PageManager::mPageSets;
54PageSet* PageManager::mCurrentSet;
55PageSet* PageManager::mBaseSet = NULL;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010056MouseCursor *PageManager::mMouseCursor = NULL;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010057HardwareKeyboard *PageManager::mHardwareKeyboard = NULL;
Dees_Troy51a0e822012-09-05 15:24:24 -040058
Ethan Yonker751a85e2014-12-12 16:59:10 -060059int tw_x_offset = 0;
60int tw_y_offset = 0;
61
Dees_Troy51a0e822012-09-05 15:24:24 -040062// Helper routine to convert a string to a color declaration
63int ConvertStrToColor(std::string str, COLOR* color)
64{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020065 // Set the default, solid black
66 memset(color, 0, sizeof(COLOR));
67 color->alpha = 255;
Dees_Troy51a0e822012-09-05 15:24:24 -040068
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020069 // Translate variables
70 DataManager::GetValue(str, str);
Matt Mowerfb1c4ff2014-04-16 13:43:36 -050071
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020072 // Look for some defaults
thatf6ed8fc2015-02-14 20:23:16 +010073 if (str == "black") return 0;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020074 else if (str == "white") { color->red = color->green = color->blue = 255; return 0; }
75 else if (str == "red") { color->red = 255; return 0; }
76 else if (str == "green") { color->green = 255; return 0; }
77 else if (str == "blue") { color->blue = 255; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040078
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020079 // At this point, we require an RGB(A) color
80 if (str[0] != '#')
81 return -1;
82
83 str.erase(0, 1);
Dees_Troy51a0e822012-09-05 15:24:24 -040084
Dees_Troy30b962e2012-10-19 20:48:59 -040085 int result;
86 if (str.size() >= 8) {
87 // We have alpha channel
88 string alpha = str.substr(6, 2);
89 result = strtol(alpha.c_str(), NULL, 16);
90 color->alpha = result & 0x000000FF;
91 str.resize(6);
92 result = strtol(str.c_str(), NULL, 16);
93 color->red = (result >> 16) & 0x000000FF;
94 color->green = (result >> 8) & 0x000000FF;
95 color->blue = result & 0x000000FF;
96 } else {
97 result = strtol(str.c_str(), NULL, 16);
98 color->red = (result >> 16) & 0x000000FF;
99 color->green = (result >> 8) & 0x000000FF;
100 color->blue = result & 0x000000FF;
101 }
102 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400103}
104
105// Helper APIs
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600106xml_node<>* FindNode(xml_node<>* parent, const char* nodename, int depth /* = 0 */)
107{
that8d46c092015-02-26 01:30:04 +0100108 if (!parent)
109 return NULL;
110
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600111 xml_node<>* child = parent->first_node(nodename);
112 if (child)
113 return child;
114
115 if (depth == 10) {
116 LOGERR("Too many style loops detected.\n");
117 return NULL;
118 }
119
120 xml_node<>* style = parent->first_node("style");
121 if (style) {
122 while (style) {
123 if (!style->first_attribute("name")) {
124 LOGERR("No name given for style.\n");
125 continue;
126 } else {
127 std::string name = style->first_attribute("name")->value();
128 xml_node<>* node = PageManager::FindStyle(name);
129
130 if (node) {
131 // We found the style that was named
132 xml_node<>* stylenode = FindNode(node, nodename, depth + 1);
133 if (stylenode)
134 return stylenode;
135 }
136 }
137 style = style->next_sibling("style");
138 }
139 } else {
140 // Search for stylename in the parent node <object type="foo" stylename="foo2">
141 xml_attribute<>* attr = parent->first_attribute("style");
142 // If no style is found anywhere else and the node wasn't found in the object itself
143 // as a special case we will search for a style that uses the same style name as the
144 // object type, so <object type="button"> would search for a style named "button"
145 if (!attr)
146 attr = parent->first_attribute("type");
147 if (attr) {
148 xml_node<>* node = PageManager::FindStyle(attr->value());
149 if (node) {
150 xml_node<>* stylenode = FindNode(node, nodename, depth + 1);
151 if (stylenode)
152 return stylenode;
153 }
154 }
155 }
156 return NULL;
157}
158
thatf6ed8fc2015-02-14 20:23:16 +0100159std::string LoadAttrString(xml_node<>* element, const char* attrname, const char* defaultvalue)
160{
161 if (!element)
162 return defaultvalue;
163
164 xml_attribute<>* attr = element->first_attribute(attrname);
165 return attr ? attr->value() : defaultvalue;
166}
167
168int LoadAttrInt(xml_node<>* element, const char* attrname, int defaultvalue)
169{
170 string value = LoadAttrString(element, attrname);
171 // resolve variables
172 DataManager::GetValue(value, value);
173 return value.empty() ? defaultvalue : atoi(value.c_str());
174}
175
176int LoadAttrIntScaleX(xml_node<>* element, const char* attrname, int defaultvalue)
177{
178 return scale_theme_x(LoadAttrInt(element, attrname, defaultvalue));
179}
180
181int LoadAttrIntScaleY(xml_node<>* element, const char* attrname, int defaultvalue)
182{
183 return scale_theme_y(LoadAttrInt(element, attrname, defaultvalue));
184}
185
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600186COLOR LoadAttrColor(xml_node<>* element, const char* attrname, bool* found_color, COLOR defaultvalue)
thatf6ed8fc2015-02-14 20:23:16 +0100187{
188 string value = LoadAttrString(element, attrname);
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600189 *found_color = !value.empty();
thatf6ed8fc2015-02-14 20:23:16 +0100190 // resolve variables
191 DataManager::GetValue(value, value);
192 COLOR ret = defaultvalue;
193 if (ConvertStrToColor(value, &ret) == 0)
194 return ret;
195 else
196 return defaultvalue;
197}
198
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600199COLOR LoadAttrColor(xml_node<>* element, const char* attrname, COLOR defaultvalue)
200{
201 bool found_color = false;
202 return LoadAttrColor(element, attrname, &found_color, defaultvalue);
203}
204
thatf6ed8fc2015-02-14 20:23:16 +0100205FontResource* LoadAttrFont(xml_node<>* element, const char* attrname)
206{
207 std::string name = LoadAttrString(element, attrname, "");
208 if (name.empty())
209 return NULL;
210 else
that74ac6062015-03-04 22:39:34 +0100211 return PageManager::GetResources()->FindFont(name);
thatf6ed8fc2015-02-14 20:23:16 +0100212}
213
214ImageResource* LoadAttrImage(xml_node<>* element, const char* attrname)
215{
216 std::string name = LoadAttrString(element, attrname, "");
217 if (name.empty())
218 return NULL;
219 else
that74ac6062015-03-04 22:39:34 +0100220 return PageManager::GetResources()->FindImage(name);
thatf6ed8fc2015-02-14 20:23:16 +0100221}
222
223AnimationResource* LoadAttrAnimation(xml_node<>* element, const char* attrname)
224{
225 std::string name = LoadAttrString(element, attrname, "");
226 if (name.empty())
227 return NULL;
228 else
that74ac6062015-03-04 22:39:34 +0100229 return PageManager::GetResources()->FindAnimation(name);
thatf6ed8fc2015-02-14 20:23:16 +0100230}
231
Dees_Troy51a0e822012-09-05 15:24:24 -0400232bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w /* = NULL */, int* h /* = NULL */, RenderObject::Placement* placement /* = NULL */)
233{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200234 if (!node)
235 return false;
Dees_Troy51a0e822012-09-05 15:24:24 -0400236
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200237 if (node->first_attribute("x"))
thatf6ed8fc2015-02-14 20:23:16 +0100238 *x = LoadAttrIntScaleX(node, "x") + tw_x_offset;
Dees_Troy51a0e822012-09-05 15:24:24 -0400239
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200240 if (node->first_attribute("y"))
thatf6ed8fc2015-02-14 20:23:16 +0100241 *y = LoadAttrIntScaleY(node, "y") + tw_y_offset;
Dees_Troy51a0e822012-09-05 15:24:24 -0400242
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200243 if (w && node->first_attribute("w"))
thatf6ed8fc2015-02-14 20:23:16 +0100244 *w = LoadAttrIntScaleX(node, "w");
Dees_Troy51a0e822012-09-05 15:24:24 -0400245
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200246 if (h && node->first_attribute("h"))
thatf6ed8fc2015-02-14 20:23:16 +0100247 *h = LoadAttrIntScaleY(node, "h");
Dees_Troy51a0e822012-09-05 15:24:24 -0400248
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200249 if (placement && node->first_attribute("placement"))
thatf6ed8fc2015-02-14 20:23:16 +0100250 *placement = (RenderObject::Placement) LoadAttrInt(node, "placement");
Dees_Troy51a0e822012-09-05 15:24:24 -0400251
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200252 return true;
Dees_Troy51a0e822012-09-05 15:24:24 -0400253}
254
255int ActionObject::SetActionPos(int x, int y, int w, int h)
256{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200257 if (x < 0 || y < 0)
258 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400259
Matt Mowerfb1c4ff2014-04-16 13:43:36 -0500260 mActionX = x;
261 mActionY = y;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200262 if (w || h)
263 {
264 mActionW = w;
265 mActionH = h;
266 }
267 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400268}
269
thatb63e2f92015-06-27 21:35:11 +0200270Page::Page(xml_node<>* page, std::vector<xml_node<>*> *templates)
Dees_Troy51a0e822012-09-05 15:24:24 -0400271{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200272 mTouchStart = NULL;
Dees_Troy51a0e822012-09-05 15:24:24 -0400273
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200274 // We can memset the whole structure, because the alpha channel is ignored
275 memset(&mBackground, 0, sizeof(COLOR));
Dees_Troy51a0e822012-09-05 15:24:24 -0400276
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200277 // With NULL, we make a console-only display
278 if (!page)
279 {
280 mName = "console";
Dees_Troy51a0e822012-09-05 15:24:24 -0400281
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200282 GUIConsole* element = new GUIConsole(NULL);
283 mRenders.push_back(element);
284 mActions.push_back(element);
285 return;
286 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400287
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200288 if (page->first_attribute("name"))
289 mName = page->first_attribute("name")->value();
290 else
291 {
292 LOGERR("No page name attribute found!\n");
293 return;
294 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400295
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200296 LOGINFO("Loading page %s\n", mName.c_str());
Dees_Troy51a0e822012-09-05 15:24:24 -0400297
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200298 // This is a recursive routine for template handling
thatb63e2f92015-06-27 21:35:11 +0200299 ProcessNode(page, templates, 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400300}
301
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100302Page::~Page()
303{
304 for (std::vector<GUIObject*>::iterator itr = mObjects.begin(); itr != mObjects.end(); ++itr)
305 delete *itr;
306}
307
thatb63e2f92015-06-27 21:35:11 +0200308bool Page::ProcessNode(xml_node<>* page, std::vector<xml_node<>*> *templates, int depth)
Dees_Troy51a0e822012-09-05 15:24:24 -0400309{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200310 if (depth == 10)
311 {
312 LOGERR("Page processing depth has exceeded 10. Failing out. This is likely a recursive template.\n");
313 return false;
314 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400315
thatb63e2f92015-06-27 21:35:11 +0200316 for (xml_node<>* child = page->first_node(); child; child = child->next_sibling())
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200317 {
thatb63e2f92015-06-27 21:35:11 +0200318 std::string type = child->name();
319
320 if (type == "background") {
321 mBackground = LoadAttrColor(child, "color", COLOR(0,0,0,0));
322 continue;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200323 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400324
thatb63e2f92015-06-27 21:35:11 +0200325 if (type == "object") {
326 // legacy format : <object type="...">
327 xml_attribute<>* attr = child->first_attribute("type");
328 type = attr ? attr->value() : "*unspecified*";
329 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400330
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200331 if (type == "text")
332 {
333 GUIText* element = new GUIText(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100334 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200335 mRenders.push_back(element);
336 mActions.push_back(element);
337 }
338 else if (type == "image")
339 {
340 GUIImage* element = new GUIImage(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100341 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200342 mRenders.push_back(element);
343 }
344 else if (type == "fill")
345 {
346 GUIFill* element = new GUIFill(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100347 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200348 mRenders.push_back(element);
349 }
350 else if (type == "action")
351 {
352 GUIAction* element = new GUIAction(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100353 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200354 mActions.push_back(element);
355 }
356 else if (type == "console")
357 {
358 GUIConsole* element = new GUIConsole(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100359 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200360 mRenders.push_back(element);
361 mActions.push_back(element);
362 }
363 else if (type == "button")
364 {
365 GUIButton* element = new GUIButton(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100366 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200367 mRenders.push_back(element);
368 mActions.push_back(element);
369 }
370 else if (type == "checkbox")
371 {
372 GUICheckbox* element = new GUICheckbox(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100373 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200374 mRenders.push_back(element);
375 mActions.push_back(element);
376 }
377 else if (type == "fileselector")
378 {
379 GUIFileSelector* element = new GUIFileSelector(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100380 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200381 mRenders.push_back(element);
382 mActions.push_back(element);
383 }
384 else if (type == "animation")
385 {
386 GUIAnimation* element = new GUIAnimation(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100387 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200388 mRenders.push_back(element);
389 }
390 else if (type == "progressbar")
391 {
392 GUIProgressBar* element = new GUIProgressBar(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100393 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200394 mRenders.push_back(element);
395 mActions.push_back(element);
396 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400397 else if (type == "slider")
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200398 {
399 GUISlider* element = new GUISlider(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100400 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200401 mRenders.push_back(element);
402 mActions.push_back(element);
403 }
Vojtech Bocek85932342013-04-01 22:11:33 +0200404 else if (type == "slidervalue")
405 {
406 GUISliderValue *element = new GUISliderValue(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100407 mObjects.push_back(element);
Vojtech Bocek85932342013-04-01 22:11:33 +0200408 mRenders.push_back(element);
409 mActions.push_back(element);
410 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400411 else if (type == "listbox")
412 {
413 GUIListBox* element = new GUIListBox(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100414 mObjects.push_back(element);
Dees_Troy51a0e822012-09-05 15:24:24 -0400415 mRenders.push_back(element);
416 mActions.push_back(element);
417 }
418 else if (type == "keyboard")
419 {
420 GUIKeyboard* element = new GUIKeyboard(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100421 mObjects.push_back(element);
Dees_Troy51a0e822012-09-05 15:24:24 -0400422 mRenders.push_back(element);
423 mActions.push_back(element);
424 }
425 else if (type == "input")
426 {
427 GUIInput* element = new GUIInput(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100428 mObjects.push_back(element);
Dees_Troy51a0e822012-09-05 15:24:24 -0400429 mRenders.push_back(element);
430 mActions.push_back(element);
431 mInputs.push_back(element);
432 }
Dees_Troya13d74f2013-03-24 08:54:55 -0500433 else if (type == "partitionlist")
434 {
435 GUIPartitionList* element = new GUIPartitionList(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100436 mObjects.push_back(element);
Dees_Troya13d74f2013-03-24 08:54:55 -0500437 mRenders.push_back(element);
438 mActions.push_back(element);
439 }
Vojtech Bocek7e11ac52015-03-05 23:21:49 +0100440 else if (type == "patternpassword")
441 {
442 GUIPatternPassword* element = new GUIPatternPassword(child);
443 mObjects.push_back(element);
444 mRenders.push_back(element);
445 mActions.push_back(element);
446 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200447 else if (type == "template")
448 {
449 if (!templates || !child->first_attribute("name"))
450 {
451 LOGERR("Invalid template request.\n");
452 }
453 else
454 {
455 std::string name = child->first_attribute("name")->value();
Ethan Yonker780cd392014-07-21 15:24:39 -0500456 xml_node<>* node;
457 bool node_found = false;
Dees_Troy51a0e822012-09-05 15:24:24 -0400458
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200459 // We need to find the correct template
Ethan Yonker780cd392014-07-21 15:24:39 -0500460 for (std::vector<xml_node<>*>::iterator itr = templates->begin(); itr != templates->end(); itr++) {
461 node = (*itr)->first_node("template");
Dees_Troy51a0e822012-09-05 15:24:24 -0400462
Ethan Yonker780cd392014-07-21 15:24:39 -0500463 while (node)
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200464 {
Ethan Yonker780cd392014-07-21 15:24:39 -0500465 if (!node->first_attribute("name"))
466 continue;
467
468 if (name == node->first_attribute("name")->value())
469 {
470 if (!ProcessNode(node, templates, depth + 1))
471 return false;
472 else {
473 node_found = true;
474 break;
475 }
476 }
477 if (node_found)
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200478 break;
Ethan Yonker780cd392014-07-21 15:24:39 -0500479 node = node->next_sibling("template");
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200480 }
thatb63e2f92015-06-27 21:35:11 +0200481 // [check] why is there no if (node_found) here too?
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200482 }
483 }
484 }
485 else
486 {
thatb63e2f92015-06-27 21:35:11 +0200487 LOGERR("Unknown object type: %s.\n", type.c_str());
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200488 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200489 }
490 return true;
Dees_Troy51a0e822012-09-05 15:24:24 -0400491}
492
493int Page::Render(void)
494{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200495 // Render background
496 gr_color(mBackground.red, mBackground.green, mBackground.blue, mBackground.alpha);
497 gr_fill(0, 0, gr_fb_width(), gr_fb_height());
Dees_Troy51a0e822012-09-05 15:24:24 -0400498
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200499 // Render remaining objects
500 std::vector<RenderObject*>::iterator iter;
501 for (iter = mRenders.begin(); iter != mRenders.end(); iter++)
502 {
503 if ((*iter)->Render())
504 LOGERR("A render request has failed.\n");
505 }
506 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400507}
508
509int Page::Update(void)
510{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200511 int retCode = 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400512
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200513 std::vector<RenderObject*>::iterator iter;
514 for (iter = mRenders.begin(); iter != mRenders.end(); iter++)
515 {
516 int ret = (*iter)->Update();
517 if (ret < 0)
518 LOGERR("An update request has failed.\n");
519 else if (ret > retCode)
520 retCode = ret;
521 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400522
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200523 return retCode;
Dees_Troy51a0e822012-09-05 15:24:24 -0400524}
525
526int Page::NotifyTouch(TOUCH_STATE state, int x, int y)
527{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200528 // By default, return 1 to ignore further touches if nobody is listening
529 int ret = 1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400530
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200531 // Don't try to handle a lack of handlers
532 if (mActions.size() == 0)
533 return ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400534
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200535 // We record mTouchStart so we can pass all the touch stream to the same handler
536 if (state == TOUCH_START)
537 {
538 std::vector<ActionObject*>::reverse_iterator iter;
539 // We work backwards, from top-most element to bottom-most element
540 for (iter = mActions.rbegin(); iter != mActions.rend(); iter++)
541 {
542 if ((*iter)->IsInRegion(x, y))
543 {
544 mTouchStart = (*iter);
545 ret = mTouchStart->NotifyTouch(state, x, y);
546 if (ret >= 0)
547 break;
548 mTouchStart = NULL;
549 }
550 }
551 }
552 else if (state == TOUCH_RELEASE && mTouchStart != NULL)
553 {
554 ret = mTouchStart->NotifyTouch(state, x, y);
555 mTouchStart = NULL;
556 }
557 else if ((state == TOUCH_DRAG || state == TOUCH_HOLD || state == TOUCH_REPEAT) && mTouchStart != NULL)
558 {
559 ret = mTouchStart->NotifyTouch(state, x, y);
560 }
561 return ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400562}
563
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100564int Page::NotifyKey(int key, bool down)
Dees_Troy51a0e822012-09-05 15:24:24 -0400565{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200566 std::vector<ActionObject*>::reverse_iterator iter;
Dees_Troy51a0e822012-09-05 15:24:24 -0400567
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200568 // Don't try to handle a lack of handlers
569 if (mActions.size() == 0)
570 return 1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400571
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100572 int ret = 1;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200573 // We work backwards, from top-most element to bottom-most element
574 for (iter = mActions.rbegin(); iter != mActions.rend(); iter++)
575 {
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100576 ret = (*iter)->NotifyKey(key, down);
577 if (ret < 0) {
578 LOGERR("An action handler has returned an error\n");
579 ret = 1;
580 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200581 }
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100582 return ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400583}
584
585int Page::NotifyKeyboard(int key)
586{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200587 std::vector<InputObject*>::reverse_iterator iter;
Dees_Troy51a0e822012-09-05 15:24:24 -0400588
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200589 // Don't try to handle a lack of handlers
590 if (mInputs.size() == 0)
591 return 1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400592
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200593 // We work backwards, from top-most element to bottom-most element
594 for (iter = mInputs.rbegin(); iter != mInputs.rend(); iter++)
595 {
596 int ret = (*iter)->NotifyKeyboard(key);
597 if (ret == 0)
598 return 0;
599 else if (ret < 0)
600 LOGERR("A keyboard handler has returned an error");
601 }
602 return 1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400603}
604
605int Page::SetKeyBoardFocus(int inFocus)
606{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200607 std::vector<InputObject*>::reverse_iterator iter;
Dees_Troy51a0e822012-09-05 15:24:24 -0400608
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200609 // Don't try to handle a lack of handlers
610 if (mInputs.size() == 0)
611 return 1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400612
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200613 // We work backwards, from top-most element to bottom-most element
614 for (iter = mInputs.rbegin(); iter != mInputs.rend(); iter++)
615 {
616 int ret = (*iter)->SetInputFocus(inFocus);
617 if (ret == 0)
618 return 0;
619 else if (ret < 0)
620 LOGERR("An input focus handler has returned an error");
621 }
622 return 1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400623}
624
625void Page::SetPageFocus(int inFocus)
626{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200627 // Render remaining objects
628 std::vector<RenderObject*>::iterator iter;
629 for (iter = mRenders.begin(); iter != mRenders.end(); iter++)
630 (*iter)->SetPageFocus(inFocus);
631
632 return;
Dees_Troy51a0e822012-09-05 15:24:24 -0400633}
634
635int Page::NotifyVarChange(std::string varName, std::string value)
636{
Vojtech Bocek07220562014-02-08 02:05:33 +0100637 std::vector<GUIObject*>::iterator iter;
638 for (iter = mObjects.begin(); iter != mObjects.end(); ++iter)
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200639 {
640 if ((*iter)->NotifyVarChange(varName, value))
641 LOGERR("An action handler errored on NotifyVarChange.\n");
642 }
643 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400644}
645
646PageSet::PageSet(char* xmlFile)
647{
that74ac6062015-03-04 22:39:34 +0100648 mResources = new ResourceManager;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200649 mCurrentPage = NULL;
Dees_Troy51a0e822012-09-05 15:24:24 -0400650
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200651 mXmlFile = xmlFile;
652 if (xmlFile)
653 mDoc.parse<0>(mXmlFile);
654 else
thatb63e2f92015-06-27 21:35:11 +0200655 mCurrentPage = new Page(NULL, NULL);
Dees_Troy51a0e822012-09-05 15:24:24 -0400656}
657
658PageSet::~PageSet()
659{
Ethan Yonker1c273312015-03-16 12:18:56 -0500660 mOverlays.clear();
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100661 for (std::vector<Page*>::iterator itr = mPages.begin(); itr != mPages.end(); ++itr)
662 delete *itr;
663
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200664 delete mResources;
665 free(mXmlFile);
Vojtech Boceke979abd2015-01-12 18:29:12 +0100666
667 mDoc.clear();
668
669 for (std::vector<xml_document<>*>::iterator itr = mIncludedDocs.begin(); itr != mIncludedDocs.end(); ++itr) {
670 (*itr)->clear();
671 delete *itr;
672 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400673}
674
675int PageSet::Load(ZipArchive* package)
676{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200677 xml_node<>* parent;
678 xml_node<>* child;
Ethan Yonker780cd392014-07-21 15:24:39 -0500679 xml_node<>* xmltemplate;
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600680 xml_node<>* xmlstyle;
Matt Mowerfb1c4ff2014-04-16 13:43:36 -0500681
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200682 parent = mDoc.first_node("recovery");
683 if (!parent)
684 parent = mDoc.first_node("install");
Dees_Troy51a0e822012-09-05 15:24:24 -0400685
Ethan Yonker63e414f2015-02-06 15:44:39 -0600686 set_scale_values(1, 1); // Reset any previous scaling values
687
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200688 // Now, let's parse the XML
Ethan Yonker63e414f2015-02-06 15:44:39 -0600689 LOGINFO("Checking resolution...\n");
690 child = parent->first_node("details");
691 if (child) {
692 xml_node<>* resolution = child->first_node("resolution");
693 if (resolution) {
694 xml_attribute<>* width_attr = resolution->first_attribute("width");
695 xml_attribute<>* height_attr = resolution->first_attribute("height");
696 xml_attribute<>* noscale_attr = resolution->first_attribute("noscaling");
697 if (width_attr && height_attr && !noscale_attr) {
698 int width = atoi(width_attr->value());
699 int height = atoi(height_attr->value());
700 int offx = 0, offy = 0;
701#ifdef TW_ROUND_SCREEN
702 xml_node<>* roundscreen = child->first_node("roundscreen");
703 if (roundscreen) {
704 LOGINFO("TW_ROUND_SCREEN := true, using round screen XML settings.\n");
705 xml_attribute<>* offx_attr = roundscreen->first_attribute("offset_x");
706 xml_attribute<>* offy_attr = roundscreen->first_attribute("offset_y");
707 if (offx_attr) {
708 offx = atoi(offx_attr->value());
709 }
710 if (offy_attr) {
711 offy = atoi(offy_attr->value());
712 }
713 }
714#endif
715 if (width != 0 && height != 0) {
716 float scale_w = ((float)gr_fb_width() - ((float)offx * 2.0)) / (float)width;
717 float scale_h = ((float)gr_fb_height() - ((float)offy * 2.0)) / (float)height;
718#ifdef TW_ROUND_SCREEN
719 float scale_off_w = (float)gr_fb_width() / (float)width;
720 float scale_off_h = (float)gr_fb_height() / (float)height;
721 tw_x_offset = offx * scale_off_w;
722 tw_y_offset = offy * scale_off_h;
723#endif
724 if (scale_w != 1 || scale_h != 1) {
725 LOGINFO("Scaling theme width %fx and height %fx, offsets x: %i y: %i\n", scale_w, scale_h, tw_x_offset, tw_y_offset);
726 set_scale_values(scale_w, scale_h);
727 }
728 }
729 } else {
730 LOGINFO("XML does not contain width and height, no scaling will be applied\n");
731 }
732 } else {
733 LOGINFO("XML contains no resolution tag, no scaling will be applied.\n");
734 }
735 } else {
736 LOGINFO("XML contains no details tag, no scaling will be applied.\n");
737 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200738 LOGINFO("Loading resources...\n");
739 child = parent->first_node("resources");
740 if (child)
that74ac6062015-03-04 22:39:34 +0100741 mResources->LoadResources(child, package);
Dees_Troy51a0e822012-09-05 15:24:24 -0400742
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200743 LOGINFO("Loading variables...\n");
744 child = parent->first_node("variables");
745 if (child)
746 LoadVariables(child);
Dees_Troy51a0e822012-09-05 15:24:24 -0400747
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100748 LOGINFO("Loading mouse cursor...\n");
749 child = parent->first_node("mousecursor");
750 if(child)
751 PageManager::LoadCursorData(child);
752
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200753 LOGINFO("Loading pages...\n");
754 // This may be NULL if no templates are present
Ethan Yonker780cd392014-07-21 15:24:39 -0500755 xmltemplate = parent->first_node("templates");
756 if (xmltemplate)
757 templates.push_back(xmltemplate);
Dees_Troy51a0e822012-09-05 15:24:24 -0400758
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600759 // Load styles if present
760 xmlstyle = parent->first_node("styles");
761 if (xmlstyle)
762 styles.push_back(xmlstyle);
763
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200764 child = parent->first_node("pages");
Ethan Yonker780cd392014-07-21 15:24:39 -0500765 if (child) {
766 if (LoadPages(child)) {
767 LOGERR("PageSet::Load returning -1\n");
768 return -1;
769 }
770 }
Vojtech Boceke979abd2015-01-12 18:29:12 +0100771
Ethan Yonker780cd392014-07-21 15:24:39 -0500772 return CheckInclude(package, &mDoc);
773}
Dees_Troy51a0e822012-09-05 15:24:24 -0400774
Ethan Yonker780cd392014-07-21 15:24:39 -0500775int PageSet::CheckInclude(ZipArchive* package, xml_document<> *parentDoc)
776{
777 xml_node<>* par;
778 xml_node<>* par2;
779 xml_node<>* chld;
780 xml_node<>* parent;
781 xml_node<>* child;
782 xml_node<>* xmltemplate;
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600783 xml_node<>* xmlstyle;
Ethan Yonker780cd392014-07-21 15:24:39 -0500784 long len;
785 char* xmlFile = NULL;
786 string filename;
Vojtech Boceke979abd2015-01-12 18:29:12 +0100787 xml_document<> *doc = NULL;
Ethan Yonker780cd392014-07-21 15:24:39 -0500788
789 par = parentDoc->first_node("recovery");
790 if (!par) {
791 par = parentDoc->first_node("install");
792 }
793 if (!par) {
794 return 0;
795 }
796
797 par2 = par->first_node("include");
798 if (!par2)
799 return 0;
800 chld = par2->first_node("xmlfile");
801 while (chld != NULL) {
802 xml_attribute<>* attr = chld->first_attribute("name");
803 if (!attr)
804 break;
805
Ethan Yonker780cd392014-07-21 15:24:39 -0500806 if (!package) {
807 // We can try to load the XML directly...
Dees Troy3454ade2015-01-20 19:21:04 +0000808 filename = TWRES;
Ethan Yonker780cd392014-07-21 15:24:39 -0500809 filename += attr->value();
Dees Troy3454ade2015-01-20 19:21:04 +0000810 LOGINFO("PageSet::CheckInclude loading filename: '%s'\n", filename.c_str());
Ethan Yonker780cd392014-07-21 15:24:39 -0500811 struct stat st;
812 if(stat(filename.c_str(),&st) != 0) {
813 LOGERR("Unable to locate '%s'\n", filename.c_str());
814 return -1;
815 }
816
817 len = st.st_size;
818 xmlFile = (char*) malloc(len + 1);
819 if (!xmlFile)
820 return -1;
821
822 int fd = open(filename.c_str(), O_RDONLY);
823 if (fd == -1)
824 return -1;
825
826 read(fd, xmlFile, len);
827 close(fd);
828 } else {
829 filename += attr->value();
Dees Troy3454ade2015-01-20 19:21:04 +0000830 LOGINFO("PageSet::CheckInclude loading filename: '%s'\n", filename.c_str());
Ethan Yonker780cd392014-07-21 15:24:39 -0500831 const ZipEntry* ui_xml = mzFindZipEntry(package, filename.c_str());
832 if (ui_xml == NULL)
833 {
834 LOGERR("Unable to locate '%s' in zip file\n", filename.c_str());
835 return -1;
836 }
837
838 // Allocate the buffer for the file
839 len = mzGetZipEntryUncompLen(ui_xml);
840 xmlFile = (char*) malloc(len + 1);
841 if (!xmlFile)
842 return -1;
843
844 if (!mzExtractZipEntryToBuffer(package, ui_xml, (unsigned char*) xmlFile))
845 {
846 LOGERR("Unable to extract '%s'\n", filename.c_str());
847 return -1;
848 }
849 }
Ethan Yonker780cd392014-07-21 15:24:39 -0500850
Vojtech Boceke979abd2015-01-12 18:29:12 +0100851 xmlFile[len] = '\0';
852 doc = new xml_document<>();
853 doc->parse<0>(xmlFile);
854
855 parent = doc->first_node("recovery");
Ethan Yonker780cd392014-07-21 15:24:39 -0500856 if (!parent)
Vojtech Boceke979abd2015-01-12 18:29:12 +0100857 parent = doc->first_node("install");
Ethan Yonker780cd392014-07-21 15:24:39 -0500858
859 // Now, let's parse the XML
860 LOGINFO("Loading included resources...\n");
861 child = parent->first_node("resources");
862 if (child)
863 mResources->LoadResources(child, package);
864
865 LOGINFO("Loading included variables...\n");
866 child = parent->first_node("variables");
867 if (child)
868 LoadVariables(child);
869
870 LOGINFO("Loading mouse cursor...\n");
871 child = parent->first_node("mousecursor");
872 if(child)
873 PageManager::LoadCursorData(child);
874
875 LOGINFO("Loading included pages...\n");
876 // This may be NULL if no templates are present
877 xmltemplate = parent->first_node("templates");
878 if (xmltemplate)
879 templates.push_back(xmltemplate);
880
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600881 // Load styles if present
882 xmlstyle = parent->first_node("styles");
883 if (xmlstyle)
884 styles.push_back(xmlstyle);
885
Ethan Yonker780cd392014-07-21 15:24:39 -0500886 child = parent->first_node("pages");
Vojtech Boceke979abd2015-01-12 18:29:12 +0100887 if (child && LoadPages(child))
888 {
889 templates.pop_back();
890 doc->clear();
891 delete doc;
892 return -1;
893 }
Ethan Yonker780cd392014-07-21 15:24:39 -0500894
Vojtech Boceke979abd2015-01-12 18:29:12 +0100895 mIncludedDocs.push_back(doc);
896
897 if (CheckInclude(package, doc))
Ethan Yonker780cd392014-07-21 15:24:39 -0500898 return -1;
899
900 chld = chld->next_sibling("xmlfile");
901 }
902
903 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400904}
905
906int PageSet::SetPage(std::string page)
907{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200908 Page* tmp = FindPage(page);
909 if (tmp)
910 {
911 if (mCurrentPage) mCurrentPage->SetPageFocus(0);
912 mCurrentPage = tmp;
913 mCurrentPage->SetPageFocus(1);
914 mCurrentPage->NotifyVarChange("", "");
915 return 0;
916 }
917 else
918 {
919 LOGERR("Unable to locate page (%s)\n", page.c_str());
920 }
921 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400922}
923
924int PageSet::SetOverlay(Page* page)
925{
Ethan Yonker1c273312015-03-16 12:18:56 -0500926 if (page) {
927 if (mOverlays.size() >= 10) {
928 LOGERR("Too many overlays requested, max is 10.\n");
929 return -1;
930 }
Matt Mowerd411f8d2015-04-09 16:04:12 -0500931
932 std::vector<Page*>::iterator iter;
933 for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) {
934 if ((*iter)->GetName() == page->GetName()) {
935 mOverlays.erase(iter);
936 // SetOverlay() is (and should stay) the only function which
937 // adds to mOverlays. Then, each page can appear at most once.
938 break;
939 }
940 }
941
Ethan Yonker1c273312015-03-16 12:18:56 -0500942 page->SetPageFocus(1);
943 page->NotifyVarChange("", "");
944
945 if (!mOverlays.empty())
946 mOverlays.back()->SetPageFocus(0);
947
948 mOverlays.push_back(page);
949 } else {
950 if (!mOverlays.empty()) {
951 mOverlays.back()->SetPageFocus(0);
952 mOverlays.pop_back();
953 if (!mOverlays.empty())
954 mOverlays.back()->SetPageFocus(1);
955 else if (mCurrentPage)
956 mCurrentPage->SetPageFocus(1); // Just in case somehow the regular page lost focus, we'll set it again
957 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200958 }
959 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400960}
961
that74ac6062015-03-04 22:39:34 +0100962const ResourceManager* PageSet::GetResources()
Dees_Troy51a0e822012-09-05 15:24:24 -0400963{
that74ac6062015-03-04 22:39:34 +0100964 return mResources;
Dees_Troy51a0e822012-09-05 15:24:24 -0400965}
966
967Page* PageSet::FindPage(std::string name)
968{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200969 std::vector<Page*>::iterator iter;
Dees_Troy51a0e822012-09-05 15:24:24 -0400970
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200971 for (iter = mPages.begin(); iter != mPages.end(); iter++)
972 {
973 if (name == (*iter)->GetName())
974 return (*iter);
975 }
976 return NULL;
Dees_Troy51a0e822012-09-05 15:24:24 -0400977}
978
979int PageSet::LoadVariables(xml_node<>* vars)
980{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200981 xml_node<>* child;
Vojtech Bocek81c29dc2013-12-07 23:02:09 +0100982 xml_attribute<> *name, *value, *persist;
983 int p;
Dees_Troy51a0e822012-09-05 15:24:24 -0400984
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200985 child = vars->first_node("variable");
986 while (child)
987 {
Vojtech Bocek81c29dc2013-12-07 23:02:09 +0100988 name = child->first_attribute("name");
989 value = child->first_attribute("value");
990 persist = child->first_attribute("persist");
991 if(name && value)
992 {
Ethan Yonker751a85e2014-12-12 16:59:10 -0600993 if (strcmp(name->value(), "tw_x_offset") == 0) {
994 tw_x_offset = atoi(value->value());
995 child = child->next_sibling("variable");
996 continue;
997 }
998 if (strcmp(name->value(), "tw_y_offset") == 0) {
999 tw_y_offset = atoi(value->value());
1000 child = child->next_sibling("variable");
1001 continue;
1002 }
Vojtech Bocek81c29dc2013-12-07 23:02:09 +01001003 p = persist ? atoi(persist->value()) : 0;
Ethan Yonker96acb3d2014-08-05 09:20:30 -05001004 string temp = value->value();
1005 string valstr = gui_parse_text(temp);
1006
1007 if (valstr.find("+") != string::npos) {
1008 string val1str = valstr;
1009 val1str = val1str.substr(0, val1str.find('+'));
1010 string val2str = valstr;
1011 val2str = val2str.substr(val2str.find('+') + 1, string::npos);
1012 int val1 = atoi(val1str.c_str());
1013 int val2 = atoi(val2str.c_str());
1014 int val = val1 + val2;
1015
1016 DataManager::SetValue(name->value(), val, p);
1017 } else if (valstr.find("-") != string::npos) {
1018 string val1str = valstr;
1019 val1str = val1str.substr(0, val1str.find('-'));
1020 string val2str = valstr;
1021 val2str = val2str.substr(val2str.find('-') + 1, string::npos);
1022 int val1 = atoi(val1str.c_str());
1023 int val2 = atoi(val2str.c_str());
1024 int val = val1 - val2;
1025
1026 DataManager::SetValue(name->value(), val, p);
1027 } else {
1028 DataManager::SetValue(name->value(), valstr, p);
1029 }
Vojtech Bocek81c29dc2013-12-07 23:02:09 +01001030 }
Dees_Troy51a0e822012-09-05 15:24:24 -04001031
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001032 child = child->next_sibling("variable");
1033 }
1034 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -04001035}
1036
Ethan Yonker780cd392014-07-21 15:24:39 -05001037int PageSet::LoadPages(xml_node<>* pages)
Dees_Troy51a0e822012-09-05 15:24:24 -04001038{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001039 xml_node<>* child;
Dees_Troy51a0e822012-09-05 15:24:24 -04001040
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001041 if (!pages)
1042 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -04001043
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001044 child = pages->first_node("page");
1045 while (child != NULL)
1046 {
Ethan Yonker780cd392014-07-21 15:24:39 -05001047 Page* page = new Page(child, &templates);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001048 if (page->GetName().empty())
1049 {
1050 LOGERR("Unable to process load page\n");
1051 delete page;
1052 }
1053 else
1054 {
1055 mPages.push_back(page);
1056 }
1057 child = child->next_sibling("page");
1058 }
1059 if (mPages.size() > 0)
1060 return 0;
1061 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -04001062}
1063
1064int PageSet::IsCurrentPage(Page* page)
1065{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001066 return ((mCurrentPage && mCurrentPage == page) ? 1 : 0);
Dees_Troy51a0e822012-09-05 15:24:24 -04001067}
1068
1069int PageSet::Render(void)
1070{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001071 int ret;
Dees_Troy51a0e822012-09-05 15:24:24 -04001072
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001073 ret = (mCurrentPage ? mCurrentPage->Render() : -1);
1074 if (ret < 0)
1075 return ret;
Ethan Yonker1c273312015-03-16 12:18:56 -05001076
1077 std::vector<Page*>::iterator iter;
1078
1079 for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) {
1080 ret = ((*iter) ? (*iter)->Render() : -1);
1081 if (ret < 0)
1082 return ret;
1083 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001084 return ret;
Dees_Troy51a0e822012-09-05 15:24:24 -04001085}
1086
1087int PageSet::Update(void)
1088{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001089 int ret;
Dees_Troy51a0e822012-09-05 15:24:24 -04001090
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001091 ret = (mCurrentPage ? mCurrentPage->Update() : -1);
1092 if (ret < 0 || ret > 1)
1093 return ret;
Ethan Yonker1c273312015-03-16 12:18:56 -05001094
1095 std::vector<Page*>::iterator iter;
1096
1097 for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) {
1098 ret = ((*iter) ? (*iter)->Update() : -1);
1099 if (ret < 0)
1100 return ret;
1101 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001102 return ret;
Dees_Troy51a0e822012-09-05 15:24:24 -04001103}
1104
1105int PageSet::NotifyTouch(TOUCH_STATE state, int x, int y)
1106{
Ethan Yonker1c273312015-03-16 12:18:56 -05001107 if (!mOverlays.empty())
1108 return mOverlays.back()->NotifyTouch(state, x, y);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001109
1110 return (mCurrentPage ? mCurrentPage->NotifyTouch(state, x, y) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001111}
1112
Vojtech Bocek0b7fe502014-03-13 17:36:52 +01001113int PageSet::NotifyKey(int key, bool down)
Dees_Troy51a0e822012-09-05 15:24:24 -04001114{
Ethan Yonker1c273312015-03-16 12:18:56 -05001115 if (!mOverlays.empty())
1116 return mOverlays.back()->NotifyKey(key, down);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001117
Vojtech Bocek0b7fe502014-03-13 17:36:52 +01001118 return (mCurrentPage ? mCurrentPage->NotifyKey(key, down) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001119}
1120
1121int PageSet::NotifyKeyboard(int key)
1122{
Ethan Yonker1c273312015-03-16 12:18:56 -05001123 if (!mOverlays.empty())
1124 return mOverlays.back()->NotifyKeyboard(key);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001125
1126 return (mCurrentPage ? mCurrentPage->NotifyKeyboard(key) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001127}
1128
1129int PageSet::SetKeyBoardFocus(int inFocus)
1130{
Ethan Yonker1c273312015-03-16 12:18:56 -05001131 if (!mOverlays.empty())
1132 return mOverlays.back()->SetKeyBoardFocus(inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001133
1134 return (mCurrentPage ? mCurrentPage->SetKeyBoardFocus(inFocus) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001135}
1136
1137int PageSet::NotifyVarChange(std::string varName, std::string value)
1138{
Ethan Yonker1c273312015-03-16 12:18:56 -05001139 std::vector<Page*>::iterator iter;
1140
1141 for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++)
1142 (*iter)->NotifyVarChange(varName, value);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001143
1144 return (mCurrentPage ? mCurrentPage->NotifyVarChange(varName, value) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001145}
1146
1147int PageManager::LoadPackage(std::string name, std::string package, std::string startpage)
1148{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001149 int fd;
1150 ZipArchive zip, *pZip = NULL;
1151 long len;
1152 char* xmlFile = NULL;
1153 PageSet* pageSet = NULL;
1154 int ret;
Ethan Yonkera2dc2f22014-11-08 08:13:40 -06001155 MemMapping map;
Dees_Troy51a0e822012-09-05 15:24:24 -04001156
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001157 // Open the XML file
1158 LOGINFO("Loading package: %s (%s)\n", name.c_str(), package.c_str());
Ethan Yonkera2dc2f22014-11-08 08:13:40 -06001159 if (package.size() > 4 && package.substr(package.size() - 4) != ".zip")
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001160 {
Ethan Yonkera2dc2f22014-11-08 08:13:40 -06001161 LOGINFO("Load XML directly\n");
Ethan Yonker751a85e2014-12-12 16:59:10 -06001162 tw_x_offset = TW_X_OFFSET;
1163 tw_y_offset = TW_Y_OFFSET;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001164 // We can try to load the XML directly...
1165 struct stat st;
1166 if(stat(package.c_str(),&st) != 0)
1167 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -04001168
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001169 len = st.st_size;
1170 xmlFile = (char*) malloc(len + 1);
1171 if (!xmlFile)
1172 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -04001173
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001174 fd = open(package.c_str(), O_RDONLY);
1175 if (fd == -1)
1176 goto error;
Dees_Troy51a0e822012-09-05 15:24:24 -04001177
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001178 read(fd, xmlFile, len);
1179 close(fd);
1180 }
1181 else
1182 {
Ethan Yonkera2dc2f22014-11-08 08:13:40 -06001183 LOGINFO("Loading zip theme\n");
Ethan Yonker751a85e2014-12-12 16:59:10 -06001184 tw_x_offset = 0;
1185 tw_y_offset = 0;
Ethan Yonkera2dc2f22014-11-08 08:13:40 -06001186 if (!TWFunc::Path_Exists(package))
1187 return -1;
1188 if (sysMapFile(package.c_str(), &map) != 0) {
1189 LOGERR("Failed to map '%s'\n", package.c_str());
1190 return -1;
1191 }
1192 if (mzOpenZipArchive(map.addr, map.length, &zip)) {
1193 LOGERR("Unable to open zip archive '%s'\n", package.c_str());
1194 sysReleaseMap(&map);
1195 return -1;
1196 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001197 pZip = &zip;
1198 const ZipEntry* ui_xml = mzFindZipEntry(&zip, "ui.xml");
1199 if (ui_xml == NULL)
1200 {
1201 LOGERR("Unable to locate ui.xml in zip file\n");
1202 goto error;
1203 }
Matt Mowerfb1c4ff2014-04-16 13:43:36 -05001204
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001205 // Allocate the buffer for the file
1206 len = mzGetZipEntryUncompLen(ui_xml);
1207 xmlFile = (char*) malloc(len + 1);
1208 if (!xmlFile)
1209 goto error;
Matt Mowerfb1c4ff2014-04-16 13:43:36 -05001210
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001211 if (!mzExtractZipEntryToBuffer(&zip, ui_xml, (unsigned char*) xmlFile))
1212 {
1213 LOGERR("Unable to extract ui.xml\n");
1214 goto error;
1215 }
1216 }
Dees_Troy51a0e822012-09-05 15:24:24 -04001217
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001218 // NULL-terminate the string
1219 xmlFile[len] = 0x00;
Dees_Troy51a0e822012-09-05 15:24:24 -04001220
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001221 // Before loading, mCurrentSet must be the loading package so we can find resources
1222 pageSet = mCurrentSet;
1223 mCurrentSet = new PageSet(xmlFile);
1224
1225 ret = mCurrentSet->Load(pZip);
1226 if (ret == 0)
1227 {
1228 mCurrentSet->SetPage(startpage);
1229 mPageSets.insert(std::pair<std::string, PageSet*>(name, mCurrentSet));
1230 }
1231 else
1232 {
1233 LOGERR("Package %s failed to load.\n", name.c_str());
1234 }
Matt Mowerfb1c4ff2014-04-16 13:43:36 -05001235
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001236 // The first successful package we loaded is the base
1237 if (mBaseSet == NULL)
1238 mBaseSet = mCurrentSet;
1239
1240 mCurrentSet = pageSet;
1241
Ethan Yonkera2dc2f22014-11-08 08:13:40 -06001242 if (pZip) {
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001243 mzCloseZipArchive(pZip);
Ethan Yonkera2dc2f22014-11-08 08:13:40 -06001244 sysReleaseMap(&map);
1245 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001246 return ret;
Dees_Troy51a0e822012-09-05 15:24:24 -04001247
1248error:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001249 LOGERR("An internal error has occurred.\n");
Ethan Yonkera2dc2f22014-11-08 08:13:40 -06001250 if (pZip) {
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001251 mzCloseZipArchive(pZip);
Ethan Yonkera2dc2f22014-11-08 08:13:40 -06001252 sysReleaseMap(&map);
1253 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001254 if (xmlFile)
1255 free(xmlFile);
1256 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -04001257}
1258
1259PageSet* PageManager::FindPackage(std::string name)
1260{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001261 std::map<std::string, PageSet*>::iterator iter;
Dees_Troy51a0e822012-09-05 15:24:24 -04001262
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001263 iter = mPageSets.find(name);
1264 if (iter != mPageSets.end())
1265 return (*iter).second;
1266
1267 LOGERR("Unable to locate package %s\n", name.c_str());
1268 return NULL;
Dees_Troy51a0e822012-09-05 15:24:24 -04001269}
1270
1271PageSet* PageManager::SelectPackage(std::string name)
1272{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001273 LOGINFO("Switching packages (%s)\n", name.c_str());
1274 PageSet* tmp;
Dees_Troy51a0e822012-09-05 15:24:24 -04001275
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001276 tmp = FindPackage(name);
1277 if (tmp)
Vojtech Bocek07220562014-02-08 02:05:33 +01001278 {
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001279 mCurrentSet = tmp;
Vojtech Bocek07220562014-02-08 02:05:33 +01001280 mCurrentSet->NotifyVarChange("", "");
1281 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001282 else
1283 LOGERR("Unable to find package.\n");
Dees_Troy51a0e822012-09-05 15:24:24 -04001284
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001285 return mCurrentSet;
Dees_Troy51a0e822012-09-05 15:24:24 -04001286}
1287
1288int PageManager::ReloadPackage(std::string name, std::string package)
1289{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001290 std::map<std::string, PageSet*>::iterator iter;
Dees_Troy51a0e822012-09-05 15:24:24 -04001291
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001292 iter = mPageSets.find(name);
1293 if (iter == mPageSets.end())
1294 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -04001295
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +01001296 if(mMouseCursor)
1297 mMouseCursor->ResetData(gr_fb_width(), gr_fb_height());
1298
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001299 PageSet* set = (*iter).second;
1300 mPageSets.erase(iter);
Dees_Troy51a0e822012-09-05 15:24:24 -04001301
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001302 if (LoadPackage(name, package, "main") != 0)
1303 {
Dees Troy3454ade2015-01-20 19:21:04 +00001304 LOGERR("Failed to load package '%s'.\n", package.c_str());
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001305 mPageSets.insert(std::pair<std::string, PageSet*>(name, set));
1306 return -1;
1307 }
1308 if (mCurrentSet == set)
1309 SelectPackage(name);
Vojtech Bocekbfb63342014-02-08 00:32:31 +01001310 if (mBaseSet == set)
1311 mBaseSet = mCurrentSet;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001312 delete set;
1313 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -04001314}
1315
1316void PageManager::ReleasePackage(std::string name)
1317{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001318 std::map<std::string, PageSet*>::iterator iter;
Dees_Troy51a0e822012-09-05 15:24:24 -04001319
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001320 iter = mPageSets.find(name);
1321 if (iter == mPageSets.end())
1322 return;
Dees_Troy51a0e822012-09-05 15:24:24 -04001323
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001324 PageSet* set = (*iter).second;
1325 mPageSets.erase(iter);
1326 delete set;
1327 return;
Dees_Troy51a0e822012-09-05 15:24:24 -04001328}
1329
1330int PageManager::ChangePage(std::string name)
1331{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001332 DataManager::SetValue("tw_operation_state", 0);
1333 int ret = (mCurrentSet ? mCurrentSet->SetPage(name) : -1);
1334 return ret;
Dees_Troy51a0e822012-09-05 15:24:24 -04001335}
1336
1337int PageManager::ChangeOverlay(std::string name)
1338{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001339 if (name.empty())
1340 return mCurrentSet->SetOverlay(NULL);
1341 else
1342 {
1343 Page* page = mBaseSet ? mBaseSet->FindPage(name) : NULL;
1344 return mCurrentSet->SetOverlay(page);
1345 }
Dees_Troy51a0e822012-09-05 15:24:24 -04001346}
1347
that74ac6062015-03-04 22:39:34 +01001348const ResourceManager* PageManager::GetResources()
Dees_Troy51a0e822012-09-05 15:24:24 -04001349{
that74ac6062015-03-04 22:39:34 +01001350 return (mCurrentSet ? mCurrentSet->GetResources() : NULL);
Dees_Troy51a0e822012-09-05 15:24:24 -04001351}
1352
1353int PageManager::SwitchToConsole(void)
1354{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001355 PageSet* console = new PageSet(NULL);
Dees_Troy51a0e822012-09-05 15:24:24 -04001356
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001357 mCurrentSet = console;
1358 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -04001359}
1360
Ethan Yonker03a42f62014-08-08 11:03:51 -05001361int PageManager::EndConsole(void)
1362{
1363 if (mCurrentSet && mBaseSet) {
1364 delete mCurrentSet;
1365 mCurrentSet = mBaseSet;
1366 return 0;
1367 }
1368 return -1;
1369}
1370
Dees_Troy51a0e822012-09-05 15:24:24 -04001371int PageManager::IsCurrentPage(Page* page)
1372{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001373 return (mCurrentSet ? mCurrentSet->IsCurrentPage(page) : 0);
Dees_Troy51a0e822012-09-05 15:24:24 -04001374}
1375
1376int PageManager::Render(void)
1377{
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +01001378 int res = (mCurrentSet ? mCurrentSet->Render() : -1);
1379 if(mMouseCursor)
1380 mMouseCursor->Render();
1381 return res;
1382}
1383
Vojtech Bocek0b7fe502014-03-13 17:36:52 +01001384HardwareKeyboard *PageManager::GetHardwareKeyboard()
1385{
1386 if(!mHardwareKeyboard)
1387 mHardwareKeyboard = new HardwareKeyboard();
1388 return mHardwareKeyboard;
1389}
1390
Ethan Yonker21ff02a2015-02-18 14:35:00 -06001391xml_node<>* PageManager::FindStyle(std::string name)
1392{
1393 for (std::vector<xml_node<>*>::iterator itr = mCurrentSet->styles.begin(); itr != mCurrentSet->styles.end(); itr++) {
1394 xml_node<>* node = (*itr)->first_node("style");
1395
1396 while (node) {
1397 if (!node->first_attribute("name"))
1398 continue;
1399
1400 if (name == node->first_attribute("name")->value())
1401 return node;
1402 node = node->next_sibling("style");
1403 }
1404 }
1405 return NULL;
1406}
1407
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +01001408MouseCursor *PageManager::GetMouseCursor()
1409{
1410 if(!mMouseCursor)
1411 mMouseCursor = new MouseCursor(gr_fb_width(), gr_fb_height());
1412 return mMouseCursor;
1413}
1414
1415void PageManager::LoadCursorData(xml_node<>* node)
1416{
1417 if(!mMouseCursor)
1418 mMouseCursor = new MouseCursor(gr_fb_width(), gr_fb_height());
1419
1420 mMouseCursor->LoadData(node);
Dees_Troy51a0e822012-09-05 15:24:24 -04001421}
1422
1423int PageManager::Update(void)
1424{
thatfb759d42015-01-11 12:16:53 +01001425 if(blankTimer.isScreenOff())
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001426 return 0;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +01001427
1428 int res = (mCurrentSet ? mCurrentSet->Update() : -1);
1429
1430 if(mMouseCursor)
1431 {
1432 int c_res = mMouseCursor->Update();
1433 if(c_res > res)
1434 res = c_res;
1435 }
1436 return res;
Dees_Troy51a0e822012-09-05 15:24:24 -04001437}
1438
1439int PageManager::NotifyTouch(TOUCH_STATE state, int x, int y)
1440{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001441 return (mCurrentSet ? mCurrentSet->NotifyTouch(state, x, y) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001442}
1443
Vojtech Bocek0b7fe502014-03-13 17:36:52 +01001444int PageManager::NotifyKey(int key, bool down)
Dees_Troy51a0e822012-09-05 15:24:24 -04001445{
Vojtech Bocek0b7fe502014-03-13 17:36:52 +01001446 return (mCurrentSet ? mCurrentSet->NotifyKey(key, down) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001447}
1448
1449int PageManager::NotifyKeyboard(int key)
1450{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001451 return (mCurrentSet ? mCurrentSet->NotifyKeyboard(key) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001452}
1453
1454int PageManager::SetKeyBoardFocus(int inFocus)
1455{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001456 return (mCurrentSet ? mCurrentSet->SetKeyBoardFocus(inFocus) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001457}
1458
1459int PageManager::NotifyVarChange(std::string varName, std::string value)
1460{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001461 return (mCurrentSet ? mCurrentSet->NotifyVarChange(varName, value) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001462}
1463
1464extern "C" void gui_notifyVarChange(const char *name, const char* value)
1465{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001466 if (!gGuiRunning)
1467 return;
Dees_Troy51a0e822012-09-05 15:24:24 -04001468
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001469 PageManager::NotifyVarChange(name, value);
Dees_Troy51a0e822012-09-05 15:24:24 -04001470}