blob: 6586cf8aaf868ef1c4a50b76e82c8b6c83bd883c [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;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010058HardwareKeyboard *PageManager::mHardwareKeyboard = NULL;
Dees_Troy51a0e822012-09-05 15:24:24 -040059
Dees_Troy51a0e822012-09-05 15:24:24 -040060// Helper routine to convert a string to a color declaration
61int ConvertStrToColor(std::string str, COLOR* color)
62{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020063 // Set the default, solid black
64 memset(color, 0, sizeof(COLOR));
65 color->alpha = 255;
Dees_Troy51a0e822012-09-05 15:24:24 -040066
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020067 // Translate variables
68 DataManager::GetValue(str, str);
Matt Mowerfb1c4ff2014-04-16 13:43:36 -050069
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020070 // Look for some defaults
71 if (str == "black") return 0;
72 else if (str == "white") { color->red = color->green = color->blue = 255; return 0; }
73 else if (str == "red") { color->red = 255; return 0; }
74 else if (str == "green") { color->green = 255; return 0; }
75 else if (str == "blue") { color->blue = 255; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040076
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020077 // At this point, we require an RGB(A) color
78 if (str[0] != '#')
79 return -1;
80
81 str.erase(0, 1);
Dees_Troy51a0e822012-09-05 15:24:24 -040082
Dees_Troy30b962e2012-10-19 20:48:59 -040083 int result;
84 if (str.size() >= 8) {
85 // We have alpha channel
86 string alpha = str.substr(6, 2);
87 result = strtol(alpha.c_str(), NULL, 16);
88 color->alpha = result & 0x000000FF;
89 str.resize(6);
90 result = strtol(str.c_str(), NULL, 16);
91 color->red = (result >> 16) & 0x000000FF;
92 color->green = (result >> 8) & 0x000000FF;
93 color->blue = result & 0x000000FF;
94 } else {
95 result = strtol(str.c_str(), NULL, 16);
96 color->red = (result >> 16) & 0x000000FF;
97 color->green = (result >> 8) & 0x000000FF;
98 color->blue = result & 0x000000FF;
99 }
100 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400101}
102
103// Helper APIs
104bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w /* = NULL */, int* h /* = NULL */, RenderObject::Placement* placement /* = NULL */)
105{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200106 if (!node)
107 return false;
Dees_Troy51a0e822012-09-05 15:24:24 -0400108
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200109 std::string value;
110 if (node->first_attribute("x"))
111 {
112 value = node->first_attribute("x")->value();
113 DataManager::GetValue(value, value);
114 *x = atol(value.c_str());
115 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400116
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200117 if (node->first_attribute("y"))
118 {
119 value = node->first_attribute("y")->value();
120 DataManager::GetValue(value, value);
121 *y = atol(value.c_str());
122 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400123
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200124 if (w && node->first_attribute("w"))
125 {
126 value = node->first_attribute("w")->value();
127 DataManager::GetValue(value, value);
128 *w = atol(value.c_str());
129 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400130
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200131 if (h && node->first_attribute("h"))
132 {
133 value = node->first_attribute("h")->value();
134 DataManager::GetValue(value, value);
135 *h = atol(value.c_str());
136 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400137
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200138 if (placement && node->first_attribute("placement"))
139 {
140 value = node->first_attribute("placement")->value();
141 DataManager::GetValue(value, value);
142 *placement = (RenderObject::Placement) atol(value.c_str());
143 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400144
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200145 return true;
Dees_Troy51a0e822012-09-05 15:24:24 -0400146}
147
148int ActionObject::SetActionPos(int x, int y, int w, int h)
149{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200150 if (x < 0 || y < 0)
151 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400152
Matt Mowerfb1c4ff2014-04-16 13:43:36 -0500153 mActionX = x;
154 mActionY = y;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200155 if (w || h)
156 {
157 mActionW = w;
158 mActionH = h;
159 }
160 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400161}
162
163Page::Page(xml_node<>* page, xml_node<>* templates /* = NULL */)
164{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200165 mTouchStart = NULL;
Dees_Troy51a0e822012-09-05 15:24:24 -0400166
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200167 // We can memset the whole structure, because the alpha channel is ignored
168 memset(&mBackground, 0, sizeof(COLOR));
Dees_Troy51a0e822012-09-05 15:24:24 -0400169
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200170 // With NULL, we make a console-only display
171 if (!page)
172 {
173 mName = "console";
Dees_Troy51a0e822012-09-05 15:24:24 -0400174
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200175 GUIConsole* element = new GUIConsole(NULL);
176 mRenders.push_back(element);
177 mActions.push_back(element);
178 return;
179 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400180
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200181 if (page->first_attribute("name"))
182 mName = page->first_attribute("name")->value();
183 else
184 {
185 LOGERR("No page name attribute found!\n");
186 return;
187 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400188
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200189 LOGINFO("Loading page %s\n", mName.c_str());
Dees_Troy51a0e822012-09-05 15:24:24 -0400190
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200191 // This is a recursive routine for template handling
192 ProcessNode(page, templates);
Dees_Troy51a0e822012-09-05 15:24:24 -0400193
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200194 return;
Dees_Troy51a0e822012-09-05 15:24:24 -0400195}
196
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100197Page::~Page()
198{
199 for (std::vector<GUIObject*>::iterator itr = mObjects.begin(); itr != mObjects.end(); ++itr)
200 delete *itr;
201}
202
Dees_Troy51a0e822012-09-05 15:24:24 -0400203bool Page::ProcessNode(xml_node<>* page, xml_node<>* templates /* = NULL */, int depth /* = 0 */)
204{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200205 if (depth == 10)
206 {
207 LOGERR("Page processing depth has exceeded 10. Failing out. This is likely a recursive template.\n");
208 return false;
209 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400210
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200211 // Let's retrieve the background value, if any
212 xml_node<>* bg = page->first_node("background");
213 if (bg)
214 {
215 xml_attribute<>* attr = bg->first_attribute("color");
216 if (attr)
217 {
218 std::string color = attr->value();
219 ConvertStrToColor(color, &mBackground);
220 }
221 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400222
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200223 xml_node<>* child;
224 child = page->first_node("object");
225 while (child)
226 {
227 if (!child->first_attribute("type"))
228 break;
Dees_Troy51a0e822012-09-05 15:24:24 -0400229
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200230 std::string type = child->first_attribute("type")->value();
Dees_Troy51a0e822012-09-05 15:24:24 -0400231
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200232 if (type == "text")
233 {
234 GUIText* element = new GUIText(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100235 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200236 mRenders.push_back(element);
237 mActions.push_back(element);
238 }
239 else if (type == "image")
240 {
241 GUIImage* element = new GUIImage(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100242 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200243 mRenders.push_back(element);
244 }
245 else if (type == "fill")
246 {
247 GUIFill* element = new GUIFill(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100248 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200249 mRenders.push_back(element);
250 }
251 else if (type == "action")
252 {
253 GUIAction* element = new GUIAction(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100254 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200255 mActions.push_back(element);
256 }
257 else if (type == "console")
258 {
259 GUIConsole* element = new GUIConsole(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100260 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200261 mRenders.push_back(element);
262 mActions.push_back(element);
263 }
264 else if (type == "button")
265 {
266 GUIButton* element = new GUIButton(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100267 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200268 mRenders.push_back(element);
269 mActions.push_back(element);
270 }
271 else if (type == "checkbox")
272 {
273 GUICheckbox* element = new GUICheckbox(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100274 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200275 mRenders.push_back(element);
276 mActions.push_back(element);
277 }
278 else if (type == "fileselector")
279 {
280 GUIFileSelector* element = new GUIFileSelector(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100281 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200282 mRenders.push_back(element);
283 mActions.push_back(element);
284 }
285 else if (type == "animation")
286 {
287 GUIAnimation* element = new GUIAnimation(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100288 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200289 mRenders.push_back(element);
290 }
291 else if (type == "progressbar")
292 {
293 GUIProgressBar* element = new GUIProgressBar(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100294 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200295 mRenders.push_back(element);
296 mActions.push_back(element);
297 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400298 else if (type == "slider")
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200299 {
300 GUISlider* element = new GUISlider(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100301 mObjects.push_back(element);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200302 mRenders.push_back(element);
303 mActions.push_back(element);
304 }
Vojtech Bocek85932342013-04-01 22:11:33 +0200305 else if (type == "slidervalue")
306 {
307 GUISliderValue *element = new GUISliderValue(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100308 mObjects.push_back(element);
Vojtech Bocek85932342013-04-01 22:11:33 +0200309 mRenders.push_back(element);
310 mActions.push_back(element);
311 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400312 else if (type == "listbox")
313 {
314 GUIListBox* element = new GUIListBox(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100315 mObjects.push_back(element);
Dees_Troy51a0e822012-09-05 15:24:24 -0400316 mRenders.push_back(element);
317 mActions.push_back(element);
318 }
319 else if (type == "keyboard")
320 {
321 GUIKeyboard* element = new GUIKeyboard(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100322 mObjects.push_back(element);
Dees_Troy51a0e822012-09-05 15:24:24 -0400323 mRenders.push_back(element);
324 mActions.push_back(element);
325 }
326 else if (type == "input")
327 {
328 GUIInput* element = new GUIInput(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100329 mObjects.push_back(element);
Dees_Troy51a0e822012-09-05 15:24:24 -0400330 mRenders.push_back(element);
331 mActions.push_back(element);
332 mInputs.push_back(element);
333 }
Dees_Troya13d74f2013-03-24 08:54:55 -0500334 else if (type == "partitionlist")
335 {
336 GUIPartitionList* element = new GUIPartitionList(child);
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100337 mObjects.push_back(element);
Dees_Troya13d74f2013-03-24 08:54:55 -0500338 mRenders.push_back(element);
339 mActions.push_back(element);
340 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200341 else if (type == "template")
342 {
343 if (!templates || !child->first_attribute("name"))
344 {
345 LOGERR("Invalid template request.\n");
346 }
347 else
348 {
349 std::string name = child->first_attribute("name")->value();
Dees_Troy51a0e822012-09-05 15:24:24 -0400350
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200351 // We need to find the correct template
352 xml_node<>* node;
353 node = templates->first_node("template");
Dees_Troy51a0e822012-09-05 15:24:24 -0400354
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200355 while (node)
356 {
357 if (!node->first_attribute("name"))
358 continue;
Dees_Troy51a0e822012-09-05 15:24:24 -0400359
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200360 if (name == node->first_attribute("name")->value())
361 {
362 if (!ProcessNode(node, templates, depth + 1))
363 return false;
364 else
365 break;
366 }
367 node = node->next_sibling("template");
368 }
369 }
370 }
371 else
372 {
373 LOGERR("Unknown object type.\n");
374 }
375 child = child->next_sibling("object");
376 }
377 return true;
Dees_Troy51a0e822012-09-05 15:24:24 -0400378}
379
380int Page::Render(void)
381{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200382 // Render background
383 gr_color(mBackground.red, mBackground.green, mBackground.blue, mBackground.alpha);
384 gr_fill(0, 0, gr_fb_width(), gr_fb_height());
Dees_Troy51a0e822012-09-05 15:24:24 -0400385
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200386 // Render remaining objects
387 std::vector<RenderObject*>::iterator iter;
388 for (iter = mRenders.begin(); iter != mRenders.end(); iter++)
389 {
390 if ((*iter)->Render())
391 LOGERR("A render request has failed.\n");
392 }
393 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400394}
395
396int Page::Update(void)
397{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200398 int retCode = 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400399
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200400 std::vector<RenderObject*>::iterator iter;
401 for (iter = mRenders.begin(); iter != mRenders.end(); iter++)
402 {
403 int ret = (*iter)->Update();
404 if (ret < 0)
405 LOGERR("An update request has failed.\n");
406 else if (ret > retCode)
407 retCode = ret;
408 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400409
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200410 return retCode;
Dees_Troy51a0e822012-09-05 15:24:24 -0400411}
412
413int Page::NotifyTouch(TOUCH_STATE state, int x, int y)
414{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200415 // By default, return 1 to ignore further touches if nobody is listening
416 int ret = 1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400417
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200418 // Don't try to handle a lack of handlers
419 if (mActions.size() == 0)
420 return ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400421
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200422 // We record mTouchStart so we can pass all the touch stream to the same handler
423 if (state == TOUCH_START)
424 {
425 std::vector<ActionObject*>::reverse_iterator iter;
426 // We work backwards, from top-most element to bottom-most element
427 for (iter = mActions.rbegin(); iter != mActions.rend(); iter++)
428 {
429 if ((*iter)->IsInRegion(x, y))
430 {
431 mTouchStart = (*iter);
432 ret = mTouchStart->NotifyTouch(state, x, y);
433 if (ret >= 0)
434 break;
435 mTouchStart = NULL;
436 }
437 }
438 }
439 else if (state == TOUCH_RELEASE && mTouchStart != NULL)
440 {
441 ret = mTouchStart->NotifyTouch(state, x, y);
442 mTouchStart = NULL;
443 }
444 else if ((state == TOUCH_DRAG || state == TOUCH_HOLD || state == TOUCH_REPEAT) && mTouchStart != NULL)
445 {
446 ret = mTouchStart->NotifyTouch(state, x, y);
447 }
448 return ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400449}
450
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100451int Page::NotifyKey(int key, bool down)
Dees_Troy51a0e822012-09-05 15:24:24 -0400452{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200453 std::vector<ActionObject*>::reverse_iterator iter;
Dees_Troy51a0e822012-09-05 15:24:24 -0400454
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200455 // Don't try to handle a lack of handlers
456 if (mActions.size() == 0)
457 return 1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400458
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100459 int ret = 1;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200460 // We work backwards, from top-most element to bottom-most element
461 for (iter = mActions.rbegin(); iter != mActions.rend(); iter++)
462 {
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100463 ret = (*iter)->NotifyKey(key, down);
464 if (ret < 0) {
465 LOGERR("An action handler has returned an error\n");
466 ret = 1;
467 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200468 }
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100469 return ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400470}
471
472int Page::NotifyKeyboard(int key)
473{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200474 std::vector<InputObject*>::reverse_iterator iter;
Dees_Troy51a0e822012-09-05 15:24:24 -0400475
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200476 // Don't try to handle a lack of handlers
477 if (mInputs.size() == 0)
478 return 1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400479
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200480 // We work backwards, from top-most element to bottom-most element
481 for (iter = mInputs.rbegin(); iter != mInputs.rend(); iter++)
482 {
483 int ret = (*iter)->NotifyKeyboard(key);
484 if (ret == 0)
485 return 0;
486 else if (ret < 0)
487 LOGERR("A keyboard handler has returned an error");
488 }
489 return 1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400490}
491
492int Page::SetKeyBoardFocus(int inFocus)
493{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200494 std::vector<InputObject*>::reverse_iterator iter;
Dees_Troy51a0e822012-09-05 15:24:24 -0400495
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200496 // Don't try to handle a lack of handlers
497 if (mInputs.size() == 0)
498 return 1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400499
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200500 // We work backwards, from top-most element to bottom-most element
501 for (iter = mInputs.rbegin(); iter != mInputs.rend(); iter++)
502 {
503 int ret = (*iter)->SetInputFocus(inFocus);
504 if (ret == 0)
505 return 0;
506 else if (ret < 0)
507 LOGERR("An input focus handler has returned an error");
508 }
509 return 1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400510}
511
512void Page::SetPageFocus(int inFocus)
513{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200514 // Render remaining objects
515 std::vector<RenderObject*>::iterator iter;
516 for (iter = mRenders.begin(); iter != mRenders.end(); iter++)
517 (*iter)->SetPageFocus(inFocus);
518
519 return;
Dees_Troy51a0e822012-09-05 15:24:24 -0400520}
521
522int Page::NotifyVarChange(std::string varName, std::string value)
523{
Vojtech Bocek07220562014-02-08 02:05:33 +0100524 std::vector<GUIObject*>::iterator iter;
525 for (iter = mObjects.begin(); iter != mObjects.end(); ++iter)
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200526 {
527 if ((*iter)->NotifyVarChange(varName, value))
528 LOGERR("An action handler errored on NotifyVarChange.\n");
529 }
530 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400531}
532
533PageSet::PageSet(char* xmlFile)
534{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200535 mResources = NULL;
536 mCurrentPage = NULL;
537 mOverlayPage = NULL;
Dees_Troy51a0e822012-09-05 15:24:24 -0400538
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200539 mXmlFile = xmlFile;
540 if (xmlFile)
541 mDoc.parse<0>(mXmlFile);
542 else
543 mCurrentPage = new Page(NULL);
Dees_Troy51a0e822012-09-05 15:24:24 -0400544}
545
546PageSet::~PageSet()
547{
Vojtech Bocekbfb63342014-02-08 00:32:31 +0100548 for (std::vector<Page*>::iterator itr = mPages.begin(); itr != mPages.end(); ++itr)
549 delete *itr;
550
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200551 delete mResources;
552 free(mXmlFile);
Dees_Troy51a0e822012-09-05 15:24:24 -0400553}
554
555int PageSet::Load(ZipArchive* package)
556{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200557 xml_node<>* parent;
558 xml_node<>* child;
559 xml_node<>* templates;
Matt Mowerfb1c4ff2014-04-16 13:43:36 -0500560
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200561 parent = mDoc.first_node("recovery");
562 if (!parent)
563 parent = mDoc.first_node("install");
Dees_Troy51a0e822012-09-05 15:24:24 -0400564
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200565 // Now, let's parse the XML
566 LOGINFO("Loading resources...\n");
567 child = parent->first_node("resources");
568 if (child)
569 mResources = new ResourceManager(child, package);
Dees_Troy51a0e822012-09-05 15:24:24 -0400570
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200571 LOGINFO("Loading variables...\n");
572 child = parent->first_node("variables");
573 if (child)
574 LoadVariables(child);
Dees_Troy51a0e822012-09-05 15:24:24 -0400575
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100576 LOGINFO("Loading mouse cursor...\n");
577 child = parent->first_node("mousecursor");
578 if(child)
579 PageManager::LoadCursorData(child);
580
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200581 LOGINFO("Loading pages...\n");
582 // This may be NULL if no templates are present
583 templates = parent->first_node("templates");
Dees_Troy51a0e822012-09-05 15:24:24 -0400584
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200585 child = parent->first_node("pages");
586 if (!child)
587 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400588
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200589 return LoadPages(child, templates);
Dees_Troy51a0e822012-09-05 15:24:24 -0400590}
591
592int PageSet::SetPage(std::string page)
593{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200594 Page* tmp = FindPage(page);
595 if (tmp)
596 {
597 if (mCurrentPage) mCurrentPage->SetPageFocus(0);
598 mCurrentPage = tmp;
599 mCurrentPage->SetPageFocus(1);
600 mCurrentPage->NotifyVarChange("", "");
601 return 0;
602 }
603 else
604 {
605 LOGERR("Unable to locate page (%s)\n", page.c_str());
606 }
607 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400608}
609
610int PageSet::SetOverlay(Page* page)
611{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200612 if (mOverlayPage) mOverlayPage->SetPageFocus(0);
613 mOverlayPage = page;
614 if (mOverlayPage)
615 {
616 mOverlayPage->SetPageFocus(1);
617 mOverlayPage->NotifyVarChange("", "");
618 }
619 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400620}
621
622Resource* PageSet::FindResource(std::string name)
623{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200624 return mResources ? mResources->FindResource(name) : NULL;
Dees_Troy51a0e822012-09-05 15:24:24 -0400625}
626
627Page* PageSet::FindPage(std::string name)
628{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200629 std::vector<Page*>::iterator iter;
Dees_Troy51a0e822012-09-05 15:24:24 -0400630
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200631 for (iter = mPages.begin(); iter != mPages.end(); iter++)
632 {
633 if (name == (*iter)->GetName())
634 return (*iter);
635 }
636 return NULL;
Dees_Troy51a0e822012-09-05 15:24:24 -0400637}
638
639int PageSet::LoadVariables(xml_node<>* vars)
640{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200641 xml_node<>* child;
Vojtech Bocek81c29dc2013-12-07 23:02:09 +0100642 xml_attribute<> *name, *value, *persist;
643 int p;
Dees_Troy51a0e822012-09-05 15:24:24 -0400644
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200645 child = vars->first_node("variable");
646 while (child)
647 {
Vojtech Bocek81c29dc2013-12-07 23:02:09 +0100648 name = child->first_attribute("name");
649 value = child->first_attribute("value");
650 persist = child->first_attribute("persist");
651 if(name && value)
652 {
653 p = persist ? atoi(persist->value()) : 0;
654 DataManager::SetValue(name->value(), value->value(), p);
655 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400656
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200657 child = child->next_sibling("variable");
658 }
659 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400660}
661
662int PageSet::LoadPages(xml_node<>* pages, xml_node<>* templates /* = NULL */)
663{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200664 xml_node<>* child;
Dees_Troy51a0e822012-09-05 15:24:24 -0400665
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200666 if (!pages)
667 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400668
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200669 child = pages->first_node("page");
670 while (child != NULL)
671 {
672 Page* page = new Page(child, templates);
673 if (page->GetName().empty())
674 {
675 LOGERR("Unable to process load page\n");
676 delete page;
677 }
678 else
679 {
680 mPages.push_back(page);
681 }
682 child = child->next_sibling("page");
683 }
684 if (mPages.size() > 0)
685 return 0;
686 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400687}
688
689int PageSet::IsCurrentPage(Page* page)
690{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200691 return ((mCurrentPage && mCurrentPage == page) ? 1 : 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400692}
693
694int PageSet::Render(void)
695{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200696 int ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400697
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200698 ret = (mCurrentPage ? mCurrentPage->Render() : -1);
699 if (ret < 0)
700 return ret;
701 ret = (mOverlayPage ? mOverlayPage->Render() : -1);
702 return ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400703}
704
705int PageSet::Update(void)
706{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200707 int ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400708
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200709 ret = (mCurrentPage ? mCurrentPage->Update() : -1);
710 if (ret < 0 || ret > 1)
711 return ret;
712 ret = (mOverlayPage ? mOverlayPage->Update() : -1);
713 return ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400714}
715
716int PageSet::NotifyTouch(TOUCH_STATE state, int x, int y)
717{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200718 if (mOverlayPage)
719 return (mOverlayPage->NotifyTouch(state, x, y));
720
721 return (mCurrentPage ? mCurrentPage->NotifyTouch(state, x, y) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -0400722}
723
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100724int PageSet::NotifyKey(int key, bool down)
Dees_Troy51a0e822012-09-05 15:24:24 -0400725{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200726 if (mOverlayPage)
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100727 return (mOverlayPage->NotifyKey(key, down));
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200728
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100729 return (mCurrentPage ? mCurrentPage->NotifyKey(key, down) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -0400730}
731
732int PageSet::NotifyKeyboard(int key)
733{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200734 if (mOverlayPage)
735 return (mOverlayPage->NotifyKeyboard(key));
736
737 return (mCurrentPage ? mCurrentPage->NotifyKeyboard(key) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -0400738}
739
740int PageSet::SetKeyBoardFocus(int inFocus)
741{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200742 if (mOverlayPage)
743 return (mOverlayPage->SetKeyBoardFocus(inFocus));
744
745 return (mCurrentPage ? mCurrentPage->SetKeyBoardFocus(inFocus) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -0400746}
747
748int PageSet::NotifyVarChange(std::string varName, std::string value)
749{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200750 if (mOverlayPage)
751 mOverlayPage->NotifyVarChange(varName, value);
752
753 return (mCurrentPage ? mCurrentPage->NotifyVarChange(varName, value) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -0400754}
755
756int PageManager::LoadPackage(std::string name, std::string package, std::string startpage)
757{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200758 int fd;
759 ZipArchive zip, *pZip = NULL;
760 long len;
761 char* xmlFile = NULL;
762 PageSet* pageSet = NULL;
763 int ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400764
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200765 // Open the XML file
766 LOGINFO("Loading package: %s (%s)\n", name.c_str(), package.c_str());
767 if (mzOpenZipArchive(package.c_str(), &zip))
768 {
769 // We can try to load the XML directly...
770 struct stat st;
771 if(stat(package.c_str(),&st) != 0)
772 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400773
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200774 len = st.st_size;
775 xmlFile = (char*) malloc(len + 1);
776 if (!xmlFile)
777 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400778
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200779 fd = open(package.c_str(), O_RDONLY);
780 if (fd == -1)
781 goto error;
Dees_Troy51a0e822012-09-05 15:24:24 -0400782
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200783 read(fd, xmlFile, len);
784 close(fd);
785 }
786 else
787 {
788 pZip = &zip;
789 const ZipEntry* ui_xml = mzFindZipEntry(&zip, "ui.xml");
790 if (ui_xml == NULL)
791 {
792 LOGERR("Unable to locate ui.xml in zip file\n");
793 goto error;
794 }
Matt Mowerfb1c4ff2014-04-16 13:43:36 -0500795
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200796 // Allocate the buffer for the file
797 len = mzGetZipEntryUncompLen(ui_xml);
798 xmlFile = (char*) malloc(len + 1);
799 if (!xmlFile)
800 goto error;
Matt Mowerfb1c4ff2014-04-16 13:43:36 -0500801
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200802 if (!mzExtractZipEntryToBuffer(&zip, ui_xml, (unsigned char*) xmlFile))
803 {
804 LOGERR("Unable to extract ui.xml\n");
805 goto error;
806 }
807 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400808
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200809 // NULL-terminate the string
810 xmlFile[len] = 0x00;
Dees_Troy51a0e822012-09-05 15:24:24 -0400811
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200812 // Before loading, mCurrentSet must be the loading package so we can find resources
813 pageSet = mCurrentSet;
814 mCurrentSet = new PageSet(xmlFile);
815
816 ret = mCurrentSet->Load(pZip);
817 if (ret == 0)
818 {
819 mCurrentSet->SetPage(startpage);
820 mPageSets.insert(std::pair<std::string, PageSet*>(name, mCurrentSet));
821 }
822 else
823 {
824 LOGERR("Package %s failed to load.\n", name.c_str());
825 }
Matt Mowerfb1c4ff2014-04-16 13:43:36 -0500826
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200827 // The first successful package we loaded is the base
828 if (mBaseSet == NULL)
829 mBaseSet = mCurrentSet;
830
831 mCurrentSet = pageSet;
832
833 if (pZip)
834 mzCloseZipArchive(pZip);
835 return ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400836
837error:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200838 LOGERR("An internal error has occurred.\n");
839 if (pZip)
840 mzCloseZipArchive(pZip);
841 if (xmlFile)
842 free(xmlFile);
843 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400844}
845
846PageSet* PageManager::FindPackage(std::string name)
847{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200848 std::map<std::string, PageSet*>::iterator iter;
Dees_Troy51a0e822012-09-05 15:24:24 -0400849
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200850 iter = mPageSets.find(name);
851 if (iter != mPageSets.end())
852 return (*iter).second;
853
854 LOGERR("Unable to locate package %s\n", name.c_str());
855 return NULL;
Dees_Troy51a0e822012-09-05 15:24:24 -0400856}
857
858PageSet* PageManager::SelectPackage(std::string name)
859{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200860 LOGINFO("Switching packages (%s)\n", name.c_str());
861 PageSet* tmp;
Dees_Troy51a0e822012-09-05 15:24:24 -0400862
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200863 tmp = FindPackage(name);
864 if (tmp)
Vojtech Bocek07220562014-02-08 02:05:33 +0100865 {
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200866 mCurrentSet = tmp;
Vojtech Bocek07220562014-02-08 02:05:33 +0100867 mCurrentSet->NotifyVarChange("", "");
868 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200869 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
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100969HardwareKeyboard *PageManager::GetHardwareKeyboard()
970{
971 if(!mHardwareKeyboard)
972 mHardwareKeyboard = new HardwareKeyboard();
973 return mHardwareKeyboard;
974}
975
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100976MouseCursor *PageManager::GetMouseCursor()
977{
978 if(!mMouseCursor)
979 mMouseCursor = new MouseCursor(gr_fb_width(), gr_fb_height());
980 return mMouseCursor;
981}
982
983void PageManager::LoadCursorData(xml_node<>* node)
984{
985 if(!mMouseCursor)
986 mMouseCursor = new MouseCursor(gr_fb_width(), gr_fb_height());
987
988 mMouseCursor->LoadData(node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400989}
990
991int PageManager::Update(void)
992{
Ricardo Gomezc9ecd442013-07-05 16:13:52 -0700993#ifndef TW_NO_SCREEN_TIMEOUT
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200994 if(blankTimer.IsScreenOff())
995 return 0;
Ricardo Gomezc9ecd442013-07-05 16:13:52 -0700996#endif
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100997
998 int res = (mCurrentSet ? mCurrentSet->Update() : -1);
999
1000 if(mMouseCursor)
1001 {
1002 int c_res = mMouseCursor->Update();
1003 if(c_res > res)
1004 res = c_res;
1005 }
1006 return res;
Dees_Troy51a0e822012-09-05 15:24:24 -04001007}
1008
1009int PageManager::NotifyTouch(TOUCH_STATE state, int x, int y)
1010{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001011 return (mCurrentSet ? mCurrentSet->NotifyTouch(state, x, y) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001012}
1013
Vojtech Bocek0b7fe502014-03-13 17:36:52 +01001014int PageManager::NotifyKey(int key, bool down)
Dees_Troy51a0e822012-09-05 15:24:24 -04001015{
Vojtech Bocek0b7fe502014-03-13 17:36:52 +01001016 return (mCurrentSet ? mCurrentSet->NotifyKey(key, down) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001017}
1018
1019int PageManager::NotifyKeyboard(int key)
1020{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001021 return (mCurrentSet ? mCurrentSet->NotifyKeyboard(key) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001022}
1023
1024int PageManager::SetKeyBoardFocus(int inFocus)
1025{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001026 return (mCurrentSet ? mCurrentSet->SetKeyBoardFocus(inFocus) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001027}
1028
1029int PageManager::NotifyVarChange(std::string varName, std::string value)
1030{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001031 return (mCurrentSet ? mCurrentSet->NotifyVarChange(varName, value) : -1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001032}
1033
1034extern "C" void gui_notifyVarChange(const char *name, const char* value)
1035{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001036 if (!gGuiRunning)
1037 return;
Dees_Troy51a0e822012-09-05 15:24:24 -04001038
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001039 PageManager::NotifyVarChange(name, value);
Dees_Troy51a0e822012-09-05 15:24:24 -04001040}