Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 1 | /* |
| 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 Troy | 3be70a8 | 2013-10-22 14:25:12 +0000 | [diff] [blame] | 18 | |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 19 | // pages.cpp - Source to manage GUI base objects |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 20 | |
| 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 | |
| 38 | extern "C" { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 39 | #include "../twcommon.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 40 | #include "../minuitwrp/minui.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | #include "rapidxml.hpp" |
| 44 | #include "objects.hpp" |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 45 | #ifndef TW_NO_SCREEN_TIMEOUT |
gordon1337 | 0d9133d | 2013-06-08 14:17:07 +0200 | [diff] [blame] | 46 | #include "blanktimer.hpp" |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 47 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 48 | |
| 49 | extern int gGuiRunning; |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 50 | #ifndef TW_NO_SCREEN_TIMEOUT |
gordon1337 | 0d9133d | 2013-06-08 14:17:07 +0200 | [diff] [blame] | 51 | extern blanktimer blankTimer; |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 52 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 53 | |
| 54 | std::map<std::string, PageSet*> PageManager::mPageSets; |
| 55 | PageSet* PageManager::mCurrentSet; |
| 56 | PageSet* PageManager::mBaseSet = NULL; |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 57 | MouseCursor *PageManager::mMouseCursor = NULL; |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 58 | HardwareKeyboard *PageManager::mHardwareKeyboard = NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 59 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 60 | // Helper routine to convert a string to a color declaration |
| 61 | int ConvertStrToColor(std::string str, COLOR* color) |
| 62 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 63 | // Set the default, solid black |
| 64 | memset(color, 0, sizeof(COLOR)); |
| 65 | color->alpha = 255; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 66 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 67 | // Translate variables |
| 68 | DataManager::GetValue(str, str); |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame^] | 69 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 70 | // 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 76 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 77 | // At this point, we require an RGB(A) color |
| 78 | if (str[0] != '#') |
| 79 | return -1; |
| 80 | |
| 81 | str.erase(0, 1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 82 | |
Dees_Troy | 30b962e | 2012-10-19 20:48:59 -0400 | [diff] [blame] | 83 | 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | // Helper APIs |
| 104 | bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w /* = NULL */, int* h /* = NULL */, RenderObject::Placement* placement /* = NULL */) |
| 105 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 106 | if (!node) |
| 107 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 108 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 109 | 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 116 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 117 | 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 123 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 124 | 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 130 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 131 | 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 137 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 138 | 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 144 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 145 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | int ActionObject::SetActionPos(int x, int y, int w, int h) |
| 149 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 150 | if (x < 0 || y < 0) |
| 151 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 152 | |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame^] | 153 | mActionX = x; |
| 154 | mActionY = y; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 155 | if (w || h) |
| 156 | { |
| 157 | mActionW = w; |
| 158 | mActionH = h; |
| 159 | } |
| 160 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | Page::Page(xml_node<>* page, xml_node<>* templates /* = NULL */) |
| 164 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 165 | mTouchStart = NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 166 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 167 | // We can memset the whole structure, because the alpha channel is ignored |
| 168 | memset(&mBackground, 0, sizeof(COLOR)); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 169 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 170 | // With NULL, we make a console-only display |
| 171 | if (!page) |
| 172 | { |
| 173 | mName = "console"; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 174 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 175 | GUIConsole* element = new GUIConsole(NULL); |
| 176 | mRenders.push_back(element); |
| 177 | mActions.push_back(element); |
| 178 | return; |
| 179 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 180 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 181 | 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 188 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 189 | LOGINFO("Loading page %s\n", mName.c_str()); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 190 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 191 | // This is a recursive routine for template handling |
| 192 | ProcessNode(page, templates); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 193 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 194 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 195 | } |
| 196 | |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 197 | Page::~Page() |
| 198 | { |
| 199 | for (std::vector<GUIObject*>::iterator itr = mObjects.begin(); itr != mObjects.end(); ++itr) |
| 200 | delete *itr; |
| 201 | } |
| 202 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 203 | bool Page::ProcessNode(xml_node<>* page, xml_node<>* templates /* = NULL */, int depth /* = 0 */) |
| 204 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 205 | 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 210 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 211 | // 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 222 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 223 | xml_node<>* child; |
| 224 | child = page->first_node("object"); |
| 225 | while (child) |
| 226 | { |
| 227 | if (!child->first_attribute("type")) |
| 228 | break; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 229 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 230 | std::string type = child->first_attribute("type")->value(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 231 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 232 | if (type == "text") |
| 233 | { |
| 234 | GUIText* element = new GUIText(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 235 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 236 | mRenders.push_back(element); |
| 237 | mActions.push_back(element); |
| 238 | } |
| 239 | else if (type == "image") |
| 240 | { |
| 241 | GUIImage* element = new GUIImage(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 242 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 243 | mRenders.push_back(element); |
| 244 | } |
| 245 | else if (type == "fill") |
| 246 | { |
| 247 | GUIFill* element = new GUIFill(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 248 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 249 | mRenders.push_back(element); |
| 250 | } |
| 251 | else if (type == "action") |
| 252 | { |
| 253 | GUIAction* element = new GUIAction(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 254 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 255 | mActions.push_back(element); |
| 256 | } |
| 257 | else if (type == "console") |
| 258 | { |
| 259 | GUIConsole* element = new GUIConsole(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 260 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 261 | mRenders.push_back(element); |
| 262 | mActions.push_back(element); |
| 263 | } |
| 264 | else if (type == "button") |
| 265 | { |
| 266 | GUIButton* element = new GUIButton(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 267 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 268 | mRenders.push_back(element); |
| 269 | mActions.push_back(element); |
| 270 | } |
| 271 | else if (type == "checkbox") |
| 272 | { |
| 273 | GUICheckbox* element = new GUICheckbox(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 274 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 275 | mRenders.push_back(element); |
| 276 | mActions.push_back(element); |
| 277 | } |
| 278 | else if (type == "fileselector") |
| 279 | { |
| 280 | GUIFileSelector* element = new GUIFileSelector(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 281 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 282 | mRenders.push_back(element); |
| 283 | mActions.push_back(element); |
| 284 | } |
| 285 | else if (type == "animation") |
| 286 | { |
| 287 | GUIAnimation* element = new GUIAnimation(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 288 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 289 | mRenders.push_back(element); |
| 290 | } |
| 291 | else if (type == "progressbar") |
| 292 | { |
| 293 | GUIProgressBar* element = new GUIProgressBar(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 294 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 295 | mRenders.push_back(element); |
| 296 | mActions.push_back(element); |
| 297 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 298 | else if (type == "slider") |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 299 | { |
| 300 | GUISlider* element = new GUISlider(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 301 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 302 | mRenders.push_back(element); |
| 303 | mActions.push_back(element); |
| 304 | } |
Vojtech Bocek | 8593234 | 2013-04-01 22:11:33 +0200 | [diff] [blame] | 305 | else if (type == "slidervalue") |
| 306 | { |
| 307 | GUISliderValue *element = new GUISliderValue(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 308 | mObjects.push_back(element); |
Vojtech Bocek | 8593234 | 2013-04-01 22:11:33 +0200 | [diff] [blame] | 309 | mRenders.push_back(element); |
| 310 | mActions.push_back(element); |
| 311 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 312 | else if (type == "listbox") |
| 313 | { |
| 314 | GUIListBox* element = new GUIListBox(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 315 | mObjects.push_back(element); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 316 | mRenders.push_back(element); |
| 317 | mActions.push_back(element); |
| 318 | } |
| 319 | else if (type == "keyboard") |
| 320 | { |
| 321 | GUIKeyboard* element = new GUIKeyboard(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 322 | mObjects.push_back(element); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 323 | mRenders.push_back(element); |
| 324 | mActions.push_back(element); |
| 325 | } |
| 326 | else if (type == "input") |
| 327 | { |
| 328 | GUIInput* element = new GUIInput(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 329 | mObjects.push_back(element); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 330 | mRenders.push_back(element); |
| 331 | mActions.push_back(element); |
| 332 | mInputs.push_back(element); |
| 333 | } |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 334 | else if (type == "partitionlist") |
| 335 | { |
| 336 | GUIPartitionList* element = new GUIPartitionList(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 337 | mObjects.push_back(element); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 338 | mRenders.push_back(element); |
| 339 | mActions.push_back(element); |
| 340 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 341 | 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 350 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 351 | // We need to find the correct template |
| 352 | xml_node<>* node; |
| 353 | node = templates->first_node("template"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 354 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 355 | while (node) |
| 356 | { |
| 357 | if (!node->first_attribute("name")) |
| 358 | continue; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 359 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 360 | 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | int Page::Render(void) |
| 381 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 382 | // 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 385 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 386 | // 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | int Page::Update(void) |
| 397 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 398 | int retCode = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 399 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 400 | 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 409 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 410 | return retCode; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | int Page::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 414 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 415 | // By default, return 1 to ignore further touches if nobody is listening |
| 416 | int ret = 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 417 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 418 | // Don't try to handle a lack of handlers |
| 419 | if (mActions.size() == 0) |
| 420 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 421 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 422 | // 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 449 | } |
| 450 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 451 | int Page::NotifyKey(int key, bool down) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 452 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 453 | std::vector<ActionObject*>::reverse_iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 454 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 455 | // Don't try to handle a lack of handlers |
| 456 | if (mActions.size() == 0) |
| 457 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 458 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 459 | int ret = 1; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 460 | // We work backwards, from top-most element to bottom-most element |
| 461 | for (iter = mActions.rbegin(); iter != mActions.rend(); iter++) |
| 462 | { |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 463 | ret = (*iter)->NotifyKey(key, down); |
| 464 | if (ret < 0) { |
| 465 | LOGERR("An action handler has returned an error\n"); |
| 466 | ret = 1; |
| 467 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 468 | } |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 469 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | int Page::NotifyKeyboard(int key) |
| 473 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 474 | std::vector<InputObject*>::reverse_iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 475 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 476 | // Don't try to handle a lack of handlers |
| 477 | if (mInputs.size() == 0) |
| 478 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 479 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 480 | // 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | int Page::SetKeyBoardFocus(int inFocus) |
| 493 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 494 | std::vector<InputObject*>::reverse_iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 495 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 496 | // Don't try to handle a lack of handlers |
| 497 | if (mInputs.size() == 0) |
| 498 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 499 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 500 | // 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | void Page::SetPageFocus(int inFocus) |
| 513 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 514 | // 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | int Page::NotifyVarChange(std::string varName, std::string value) |
| 523 | { |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 524 | std::vector<GUIObject*>::iterator iter; |
| 525 | for (iter = mObjects.begin(); iter != mObjects.end(); ++iter) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 526 | { |
| 527 | if ((*iter)->NotifyVarChange(varName, value)) |
| 528 | LOGERR("An action handler errored on NotifyVarChange.\n"); |
| 529 | } |
| 530 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | PageSet::PageSet(char* xmlFile) |
| 534 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 535 | mResources = NULL; |
| 536 | mCurrentPage = NULL; |
| 537 | mOverlayPage = NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 538 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 539 | mXmlFile = xmlFile; |
| 540 | if (xmlFile) |
| 541 | mDoc.parse<0>(mXmlFile); |
| 542 | else |
| 543 | mCurrentPage = new Page(NULL); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | PageSet::~PageSet() |
| 547 | { |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 548 | for (std::vector<Page*>::iterator itr = mPages.begin(); itr != mPages.end(); ++itr) |
| 549 | delete *itr; |
| 550 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 551 | delete mResources; |
| 552 | free(mXmlFile); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | int PageSet::Load(ZipArchive* package) |
| 556 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 557 | xml_node<>* parent; |
| 558 | xml_node<>* child; |
| 559 | xml_node<>* templates; |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame^] | 560 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 561 | parent = mDoc.first_node("recovery"); |
| 562 | if (!parent) |
| 563 | parent = mDoc.first_node("install"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 564 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 565 | // 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 570 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 571 | LOGINFO("Loading variables...\n"); |
| 572 | child = parent->first_node("variables"); |
| 573 | if (child) |
| 574 | LoadVariables(child); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 575 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 576 | LOGINFO("Loading mouse cursor...\n"); |
| 577 | child = parent->first_node("mousecursor"); |
| 578 | if(child) |
| 579 | PageManager::LoadCursorData(child); |
| 580 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 581 | LOGINFO("Loading pages...\n"); |
| 582 | // This may be NULL if no templates are present |
| 583 | templates = parent->first_node("templates"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 584 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 585 | child = parent->first_node("pages"); |
| 586 | if (!child) |
| 587 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 588 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 589 | return LoadPages(child, templates); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | int PageSet::SetPage(std::string page) |
| 593 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 594 | 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | int PageSet::SetOverlay(Page* page) |
| 611 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 612 | if (mOverlayPage) mOverlayPage->SetPageFocus(0); |
| 613 | mOverlayPage = page; |
| 614 | if (mOverlayPage) |
| 615 | { |
| 616 | mOverlayPage->SetPageFocus(1); |
| 617 | mOverlayPage->NotifyVarChange("", ""); |
| 618 | } |
| 619 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | Resource* PageSet::FindResource(std::string name) |
| 623 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 624 | return mResources ? mResources->FindResource(name) : NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | Page* PageSet::FindPage(std::string name) |
| 628 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 629 | std::vector<Page*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 630 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 631 | for (iter = mPages.begin(); iter != mPages.end(); iter++) |
| 632 | { |
| 633 | if (name == (*iter)->GetName()) |
| 634 | return (*iter); |
| 635 | } |
| 636 | return NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | int PageSet::LoadVariables(xml_node<>* vars) |
| 640 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 641 | xml_node<>* child; |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 642 | xml_attribute<> *name, *value, *persist; |
| 643 | int p; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 644 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 645 | child = vars->first_node("variable"); |
| 646 | while (child) |
| 647 | { |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 648 | 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 656 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 657 | child = child->next_sibling("variable"); |
| 658 | } |
| 659 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | int PageSet::LoadPages(xml_node<>* pages, xml_node<>* templates /* = NULL */) |
| 663 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 664 | xml_node<>* child; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 665 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 666 | if (!pages) |
| 667 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 668 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 669 | 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | int PageSet::IsCurrentPage(Page* page) |
| 690 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 691 | return ((mCurrentPage && mCurrentPage == page) ? 1 : 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | int PageSet::Render(void) |
| 695 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 696 | int ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 697 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 698 | ret = (mCurrentPage ? mCurrentPage->Render() : -1); |
| 699 | if (ret < 0) |
| 700 | return ret; |
| 701 | ret = (mOverlayPage ? mOverlayPage->Render() : -1); |
| 702 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | int PageSet::Update(void) |
| 706 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 707 | int ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 708 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 709 | ret = (mCurrentPage ? mCurrentPage->Update() : -1); |
| 710 | if (ret < 0 || ret > 1) |
| 711 | return ret; |
| 712 | ret = (mOverlayPage ? mOverlayPage->Update() : -1); |
| 713 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | int PageSet::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 717 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 718 | if (mOverlayPage) |
| 719 | return (mOverlayPage->NotifyTouch(state, x, y)); |
| 720 | |
| 721 | return (mCurrentPage ? mCurrentPage->NotifyTouch(state, x, y) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 722 | } |
| 723 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 724 | int PageSet::NotifyKey(int key, bool down) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 725 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 726 | if (mOverlayPage) |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 727 | return (mOverlayPage->NotifyKey(key, down)); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 728 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 729 | return (mCurrentPage ? mCurrentPage->NotifyKey(key, down) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | int PageSet::NotifyKeyboard(int key) |
| 733 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 734 | if (mOverlayPage) |
| 735 | return (mOverlayPage->NotifyKeyboard(key)); |
| 736 | |
| 737 | return (mCurrentPage ? mCurrentPage->NotifyKeyboard(key) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | int PageSet::SetKeyBoardFocus(int inFocus) |
| 741 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 742 | if (mOverlayPage) |
| 743 | return (mOverlayPage->SetKeyBoardFocus(inFocus)); |
| 744 | |
| 745 | return (mCurrentPage ? mCurrentPage->SetKeyBoardFocus(inFocus) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | int PageSet::NotifyVarChange(std::string varName, std::string value) |
| 749 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 750 | if (mOverlayPage) |
| 751 | mOverlayPage->NotifyVarChange(varName, value); |
| 752 | |
| 753 | return (mCurrentPage ? mCurrentPage->NotifyVarChange(varName, value) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | int PageManager::LoadPackage(std::string name, std::string package, std::string startpage) |
| 757 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 758 | int fd; |
| 759 | ZipArchive zip, *pZip = NULL; |
| 760 | long len; |
| 761 | char* xmlFile = NULL; |
| 762 | PageSet* pageSet = NULL; |
| 763 | int ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 764 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 765 | // 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 773 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 774 | len = st.st_size; |
| 775 | xmlFile = (char*) malloc(len + 1); |
| 776 | if (!xmlFile) |
| 777 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 778 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 779 | fd = open(package.c_str(), O_RDONLY); |
| 780 | if (fd == -1) |
| 781 | goto error; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 782 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 783 | 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 Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame^] | 795 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 796 | // Allocate the buffer for the file |
| 797 | len = mzGetZipEntryUncompLen(ui_xml); |
| 798 | xmlFile = (char*) malloc(len + 1); |
| 799 | if (!xmlFile) |
| 800 | goto error; |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame^] | 801 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 802 | if (!mzExtractZipEntryToBuffer(&zip, ui_xml, (unsigned char*) xmlFile)) |
| 803 | { |
| 804 | LOGERR("Unable to extract ui.xml\n"); |
| 805 | goto error; |
| 806 | } |
| 807 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 808 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 809 | // NULL-terminate the string |
| 810 | xmlFile[len] = 0x00; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 811 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 812 | // 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 Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame^] | 826 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 827 | // 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 836 | |
| 837 | error: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 838 | LOGERR("An internal error has occurred.\n"); |
| 839 | if (pZip) |
| 840 | mzCloseZipArchive(pZip); |
| 841 | if (xmlFile) |
| 842 | free(xmlFile); |
| 843 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | PageSet* PageManager::FindPackage(std::string name) |
| 847 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 848 | std::map<std::string, PageSet*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 849 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 850 | 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | PageSet* PageManager::SelectPackage(std::string name) |
| 859 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 860 | LOGINFO("Switching packages (%s)\n", name.c_str()); |
| 861 | PageSet* tmp; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 862 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 863 | tmp = FindPackage(name); |
| 864 | if (tmp) |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 865 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 866 | mCurrentSet = tmp; |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 867 | mCurrentSet->NotifyVarChange("", ""); |
| 868 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 869 | else |
| 870 | LOGERR("Unable to find package.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 871 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 872 | return mCurrentSet; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | int PageManager::ReloadPackage(std::string name, std::string package) |
| 876 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 877 | std::map<std::string, PageSet*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 878 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 879 | iter = mPageSets.find(name); |
| 880 | if (iter == mPageSets.end()) |
| 881 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 882 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 883 | if(mMouseCursor) |
| 884 | mMouseCursor->ResetData(gr_fb_width(), gr_fb_height()); |
| 885 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 886 | PageSet* set = (*iter).second; |
| 887 | mPageSets.erase(iter); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 888 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 889 | 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 Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 897 | if (mBaseSet == set) |
| 898 | mBaseSet = mCurrentSet; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 899 | delete set; |
| 900 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | void PageManager::ReleasePackage(std::string name) |
| 904 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 905 | std::map<std::string, PageSet*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 906 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 907 | iter = mPageSets.find(name); |
| 908 | if (iter == mPageSets.end()) |
| 909 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 910 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 911 | PageSet* set = (*iter).second; |
| 912 | mPageSets.erase(iter); |
| 913 | delete set; |
| 914 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | int PageManager::ChangePage(std::string name) |
| 918 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 919 | DataManager::SetValue("tw_operation_state", 0); |
| 920 | int ret = (mCurrentSet ? mCurrentSet->SetPage(name) : -1); |
| 921 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | int PageManager::ChangeOverlay(std::string name) |
| 925 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 926 | 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | Resource* PageManager::FindResource(std::string name) |
| 936 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 937 | return (mCurrentSet ? mCurrentSet->FindResource(name) : NULL); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | Resource* PageManager::FindResource(std::string package, std::string name) |
| 941 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 942 | PageSet* tmp; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 943 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 944 | tmp = FindPackage(name); |
| 945 | return (tmp ? tmp->FindResource(name) : NULL); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | int PageManager::SwitchToConsole(void) |
| 949 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 950 | PageSet* console = new PageSet(NULL); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 951 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 952 | mCurrentSet = console; |
| 953 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | int PageManager::IsCurrentPage(Page* page) |
| 957 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 958 | return (mCurrentSet ? mCurrentSet->IsCurrentPage(page) : 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | int PageManager::Render(void) |
| 962 | { |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 963 | int res = (mCurrentSet ? mCurrentSet->Render() : -1); |
| 964 | if(mMouseCursor) |
| 965 | mMouseCursor->Render(); |
| 966 | return res; |
| 967 | } |
| 968 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 969 | HardwareKeyboard *PageManager::GetHardwareKeyboard() |
| 970 | { |
| 971 | if(!mHardwareKeyboard) |
| 972 | mHardwareKeyboard = new HardwareKeyboard(); |
| 973 | return mHardwareKeyboard; |
| 974 | } |
| 975 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 976 | MouseCursor *PageManager::GetMouseCursor() |
| 977 | { |
| 978 | if(!mMouseCursor) |
| 979 | mMouseCursor = new MouseCursor(gr_fb_width(), gr_fb_height()); |
| 980 | return mMouseCursor; |
| 981 | } |
| 982 | |
| 983 | void 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | int PageManager::Update(void) |
| 992 | { |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 993 | #ifndef TW_NO_SCREEN_TIMEOUT |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 994 | if(blankTimer.IsScreenOff()) |
| 995 | return 0; |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 996 | #endif |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 997 | |
| 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | int PageManager::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 1010 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1011 | return (mCurrentSet ? mCurrentSet->NotifyTouch(state, x, y) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1012 | } |
| 1013 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1014 | int PageManager::NotifyKey(int key, bool down) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1015 | { |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1016 | return (mCurrentSet ? mCurrentSet->NotifyKey(key, down) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | int PageManager::NotifyKeyboard(int key) |
| 1020 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1021 | return (mCurrentSet ? mCurrentSet->NotifyKeyboard(key) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | int PageManager::SetKeyBoardFocus(int inFocus) |
| 1025 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1026 | return (mCurrentSet ? mCurrentSet->SetKeyBoardFocus(inFocus) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | int PageManager::NotifyVarChange(std::string varName, std::string value) |
| 1030 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1031 | return (mCurrentSet ? mCurrentSet->NotifyVarChange(varName, value) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | extern "C" void gui_notifyVarChange(const char *name, const char* value) |
| 1035 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1036 | if (!gGuiRunning) |
| 1037 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1038 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1039 | PageManager::NotifyVarChange(name, value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1040 | } |