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> |
Ethan Yonker | 3fdcda4 | 2016-11-30 12:29:37 -0600 | [diff] [blame] | 35 | #include <dirent.h> |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 36 | #include "../twrp-functions.hpp" |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 37 | #include "../partitions.hpp" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 38 | |
| 39 | #include <string> |
Xuefer | cac6ace | 2016-02-01 02:28:55 +0800 | [diff] [blame] | 40 | #include <algorithm> |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 41 | |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 42 | #ifdef USE_MINZIP |
| 43 | #include "../minzip/SysUtil.h" |
| 44 | #else |
Ethan Yonker | 58f2132 | 2018-08-24 11:17:36 -0500 | [diff] [blame] | 45 | #include <otautil/SysUtil.h> |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 46 | #endif |
| 47 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 48 | extern "C" { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 49 | #include "../twcommon.h" |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 50 | #include "gui.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 51 | } |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 52 | #include "../zipwrap.hpp" |
Ethan Yonker | fbb4353 | 2015-12-28 21:54:50 +0100 | [diff] [blame] | 53 | #include "../minuitwrp/minui.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 54 | |
| 55 | #include "rapidxml.hpp" |
| 56 | #include "objects.hpp" |
gordon1337 | 0d9133d | 2013-06-08 14:17:07 +0200 | [diff] [blame] | 57 | #include "blanktimer.hpp" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 58 | |
that | 74bff7f | 2017-01-18 22:32:36 +0100 | [diff] [blame] | 59 | // version 2 requires theme to handle power button as action togglebacklight |
Captain Throwback | 268091d | 2020-10-22 09:33:29 -0400 | [diff] [blame] | 60 | // version 4 adds listbox support to reboot page |
| 61 | #define TW_THEME_VERSION 4 |
that | 74bff7f | 2017-01-18 22:32:36 +0100 | [diff] [blame] | 62 | |
Ethan Yonker | 8e5692f | 2016-01-21 11:21:06 -0600 | [diff] [blame] | 63 | #define TW_THEME_VER_ERR -2 |
Ethan Yonker | 1308d53 | 2016-01-14 22:21:49 -0600 | [diff] [blame] | 64 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 65 | extern int gGuiRunning; |
| 66 | |
| 67 | std::map<std::string, PageSet*> PageManager::mPageSets; |
| 68 | PageSet* PageManager::mCurrentSet; |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 69 | MouseCursor *PageManager::mMouseCursor = NULL; |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 70 | HardwareKeyboard *PageManager::mHardwareKeyboard = NULL; |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 71 | bool PageManager::mReloadTheme = false; |
| 72 | std::string PageManager::mStartPage = "main"; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 73 | std::vector<language_struct> Language_List; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 74 | |
Ethan Yonker | 751a85e | 2014-12-12 16:59:10 -0600 | [diff] [blame] | 75 | int tw_x_offset = 0; |
| 76 | int tw_y_offset = 0; |
James Christopher Adduono | dcd1e44 | 2016-11-06 13:17:34 -0500 | [diff] [blame] | 77 | int tw_w_offset = 0; |
| 78 | int tw_h_offset = 0; |
Ethan Yonker | 751a85e | 2014-12-12 16:59:10 -0600 | [diff] [blame] | 79 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 80 | // Helper routine to convert a string to a color declaration |
| 81 | int ConvertStrToColor(std::string str, COLOR* color) |
| 82 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 83 | // Set the default, solid black |
| 84 | memset(color, 0, sizeof(COLOR)); |
| 85 | color->alpha = 255; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 86 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 87 | // Translate variables |
| 88 | DataManager::GetValue(str, str); |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 89 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 90 | // Look for some defaults |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 91 | if (str == "black") return 0; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 92 | else if (str == "white") { color->red = color->green = color->blue = 255; return 0; } |
| 93 | else if (str == "red") { color->red = 255; return 0; } |
| 94 | else if (str == "green") { color->green = 255; return 0; } |
| 95 | else if (str == "blue") { color->blue = 255; return 0; } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 96 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 97 | // At this point, we require an RGB(A) color |
| 98 | if (str[0] != '#') |
| 99 | return -1; |
| 100 | |
| 101 | str.erase(0, 1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 102 | |
Dees_Troy | 30b962e | 2012-10-19 20:48:59 -0400 | [diff] [blame] | 103 | int result; |
| 104 | if (str.size() >= 8) { |
| 105 | // We have alpha channel |
| 106 | string alpha = str.substr(6, 2); |
| 107 | result = strtol(alpha.c_str(), NULL, 16); |
| 108 | color->alpha = result & 0x000000FF; |
| 109 | str.resize(6); |
| 110 | result = strtol(str.c_str(), NULL, 16); |
| 111 | color->red = (result >> 16) & 0x000000FF; |
| 112 | color->green = (result >> 8) & 0x000000FF; |
| 113 | color->blue = result & 0x000000FF; |
| 114 | } else { |
| 115 | result = strtol(str.c_str(), NULL, 16); |
| 116 | color->red = (result >> 16) & 0x000000FF; |
| 117 | color->green = (result >> 8) & 0x000000FF; |
| 118 | color->blue = result & 0x000000FF; |
| 119 | } |
| 120 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | // Helper APIs |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 124 | xml_node<>* FindNode(xml_node<>* parent, const char* nodename, int depth /* = 0 */) |
| 125 | { |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 126 | if (!parent) |
| 127 | return NULL; |
| 128 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 129 | xml_node<>* child = parent->first_node(nodename); |
| 130 | if (child) |
| 131 | return child; |
| 132 | |
| 133 | if (depth == 10) { |
| 134 | LOGERR("Too many style loops detected.\n"); |
| 135 | return NULL; |
| 136 | } |
| 137 | |
| 138 | xml_node<>* style = parent->first_node("style"); |
| 139 | if (style) { |
| 140 | while (style) { |
| 141 | if (!style->first_attribute("name")) { |
| 142 | LOGERR("No name given for style.\n"); |
| 143 | continue; |
| 144 | } else { |
| 145 | std::string name = style->first_attribute("name")->value(); |
| 146 | xml_node<>* node = PageManager::FindStyle(name); |
| 147 | |
| 148 | if (node) { |
| 149 | // We found the style that was named |
| 150 | xml_node<>* stylenode = FindNode(node, nodename, depth + 1); |
| 151 | if (stylenode) |
| 152 | return stylenode; |
| 153 | } |
| 154 | } |
| 155 | style = style->next_sibling("style"); |
| 156 | } |
| 157 | } else { |
that | 54e9c83 | 2015-11-04 21:46:01 +0100 | [diff] [blame] | 158 | // Search for stylename in the parent node <object type="foo" style="foo2"> |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 159 | xml_attribute<>* attr = parent->first_attribute("style"); |
| 160 | // If no style is found anywhere else and the node wasn't found in the object itself |
| 161 | // as a special case we will search for a style that uses the same style name as the |
| 162 | // object type, so <object type="button"> would search for a style named "button" |
| 163 | if (!attr) |
| 164 | attr = parent->first_attribute("type"); |
that | 54e9c83 | 2015-11-04 21:46:01 +0100 | [diff] [blame] | 165 | // if there's no attribute type, the object type must be the element name |
| 166 | std::string stylename = attr ? attr->value() : parent->name(); |
| 167 | xml_node<>* node = PageManager::FindStyle(stylename); |
| 168 | if (node) { |
| 169 | xml_node<>* stylenode = FindNode(node, nodename, depth + 1); |
| 170 | if (stylenode) |
| 171 | return stylenode; |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | return NULL; |
| 175 | } |
| 176 | |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 177 | std::string LoadAttrString(xml_node<>* element, const char* attrname, const char* defaultvalue) |
| 178 | { |
| 179 | if (!element) |
| 180 | return defaultvalue; |
| 181 | |
| 182 | xml_attribute<>* attr = element->first_attribute(attrname); |
| 183 | return attr ? attr->value() : defaultvalue; |
| 184 | } |
| 185 | |
| 186 | int LoadAttrInt(xml_node<>* element, const char* attrname, int defaultvalue) |
| 187 | { |
| 188 | string value = LoadAttrString(element, attrname); |
| 189 | // resolve variables |
| 190 | DataManager::GetValue(value, value); |
| 191 | return value.empty() ? defaultvalue : atoi(value.c_str()); |
| 192 | } |
| 193 | |
| 194 | int LoadAttrIntScaleX(xml_node<>* element, const char* attrname, int defaultvalue) |
| 195 | { |
| 196 | return scale_theme_x(LoadAttrInt(element, attrname, defaultvalue)); |
| 197 | } |
| 198 | |
| 199 | int LoadAttrIntScaleY(xml_node<>* element, const char* attrname, int defaultvalue) |
| 200 | { |
| 201 | return scale_theme_y(LoadAttrInt(element, attrname, defaultvalue)); |
| 202 | } |
| 203 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 204 | COLOR LoadAttrColor(xml_node<>* element, const char* attrname, bool* found_color, COLOR defaultvalue) |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 205 | { |
| 206 | string value = LoadAttrString(element, attrname); |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 207 | *found_color = !value.empty(); |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 208 | // resolve variables |
| 209 | DataManager::GetValue(value, value); |
| 210 | COLOR ret = defaultvalue; |
| 211 | if (ConvertStrToColor(value, &ret) == 0) |
| 212 | return ret; |
| 213 | else |
| 214 | return defaultvalue; |
| 215 | } |
| 216 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 217 | COLOR LoadAttrColor(xml_node<>* element, const char* attrname, COLOR defaultvalue) |
| 218 | { |
| 219 | bool found_color = false; |
| 220 | return LoadAttrColor(element, attrname, &found_color, defaultvalue); |
| 221 | } |
| 222 | |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 223 | FontResource* LoadAttrFont(xml_node<>* element, const char* attrname) |
| 224 | { |
| 225 | std::string name = LoadAttrString(element, attrname, ""); |
| 226 | if (name.empty()) |
| 227 | return NULL; |
| 228 | else |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 229 | return PageManager::GetResources()->FindFont(name); |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | ImageResource* LoadAttrImage(xml_node<>* element, const char* attrname) |
| 233 | { |
| 234 | std::string name = LoadAttrString(element, attrname, ""); |
| 235 | if (name.empty()) |
| 236 | return NULL; |
| 237 | else |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 238 | return PageManager::GetResources()->FindImage(name); |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | AnimationResource* LoadAttrAnimation(xml_node<>* element, const char* attrname) |
| 242 | { |
| 243 | std::string name = LoadAttrString(element, attrname, ""); |
| 244 | if (name.empty()) |
| 245 | return NULL; |
| 246 | else |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 247 | return PageManager::GetResources()->FindAnimation(name); |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 248 | } |
| 249 | |
Ethan Yonker | b7a54a3 | 2015-10-05 10:16:27 -0500 | [diff] [blame] | 250 | bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w /* = NULL */, int* h /* = NULL */, Placement* placement /* = NULL */) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 251 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 252 | if (!node) |
| 253 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 254 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 255 | if (node->first_attribute("x")) |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 256 | *x = LoadAttrIntScaleX(node, "x") + tw_x_offset; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 257 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 258 | if (node->first_attribute("y")) |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 259 | *y = LoadAttrIntScaleY(node, "y") + tw_y_offset; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 260 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 261 | if (w && node->first_attribute("w")) |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 262 | *w = LoadAttrIntScaleX(node, "w"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 263 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 264 | if (h && node->first_attribute("h")) |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 265 | *h = LoadAttrIntScaleY(node, "h"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 266 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 267 | if (placement && node->first_attribute("placement")) |
Ethan Yonker | b7a54a3 | 2015-10-05 10:16:27 -0500 | [diff] [blame] | 268 | *placement = (Placement) LoadAttrInt(node, "placement"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 269 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 270 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | int ActionObject::SetActionPos(int x, int y, int w, int h) |
| 274 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 275 | if (x < 0 || y < 0) |
| 276 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 277 | |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 278 | mActionX = x; |
| 279 | mActionY = y; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 280 | if (w || h) |
| 281 | { |
| 282 | mActionW = w; |
| 283 | mActionH = h; |
| 284 | } |
| 285 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 286 | } |
| 287 | |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 288 | Page::Page(xml_node<>* page, std::vector<xml_node<>*> *templates) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 289 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 290 | mTouchStart = NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 291 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 292 | // We can memset the whole structure, because the alpha channel is ignored |
| 293 | memset(&mBackground, 0, sizeof(COLOR)); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 294 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 295 | // With NULL, we make a console-only display |
| 296 | if (!page) |
| 297 | { |
| 298 | mName = "console"; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 299 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 300 | GUIConsole* element = new GUIConsole(NULL); |
| 301 | mRenders.push_back(element); |
| 302 | mActions.push_back(element); |
| 303 | return; |
| 304 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 305 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 306 | if (page->first_attribute("name")) |
| 307 | mName = page->first_attribute("name")->value(); |
| 308 | else |
| 309 | { |
| 310 | LOGERR("No page name attribute found!\n"); |
| 311 | return; |
| 312 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 313 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 314 | LOGINFO("Loading page %s\n", mName.c_str()); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 315 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 316 | // This is a recursive routine for template handling |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 317 | ProcessNode(page, templates, 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 318 | } |
| 319 | |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 320 | Page::~Page() |
| 321 | { |
| 322 | for (std::vector<GUIObject*>::iterator itr = mObjects.begin(); itr != mObjects.end(); ++itr) |
| 323 | delete *itr; |
| 324 | } |
| 325 | |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 326 | bool Page::ProcessNode(xml_node<>* page, std::vector<xml_node<>*> *templates, int depth) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 327 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 328 | if (depth == 10) |
| 329 | { |
| 330 | LOGERR("Page processing depth has exceeded 10. Failing out. This is likely a recursive template.\n"); |
| 331 | return false; |
| 332 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 333 | |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 334 | for (xml_node<>* child = page->first_node(); child; child = child->next_sibling()) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 335 | { |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 336 | std::string type = child->name(); |
| 337 | |
| 338 | if (type == "background") { |
| 339 | mBackground = LoadAttrColor(child, "color", COLOR(0,0,0,0)); |
| 340 | continue; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 341 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 342 | |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 343 | if (type == "object") { |
| 344 | // legacy format : <object type="..."> |
| 345 | xml_attribute<>* attr = child->first_attribute("type"); |
| 346 | type = attr ? attr->value() : "*unspecified*"; |
| 347 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 348 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 349 | if (type == "text") |
| 350 | { |
| 351 | GUIText* element = new GUIText(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 352 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 353 | mRenders.push_back(element); |
| 354 | mActions.push_back(element); |
| 355 | } |
| 356 | else if (type == "image") |
| 357 | { |
| 358 | GUIImage* element = new GUIImage(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 359 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 360 | mRenders.push_back(element); |
| 361 | } |
| 362 | else if (type == "fill") |
| 363 | { |
| 364 | GUIFill* element = new GUIFill(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 365 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 366 | mRenders.push_back(element); |
| 367 | } |
| 368 | else if (type == "action") |
| 369 | { |
| 370 | GUIAction* element = new GUIAction(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 371 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 372 | mActions.push_back(element); |
| 373 | } |
| 374 | else if (type == "console") |
| 375 | { |
| 376 | GUIConsole* element = new GUIConsole(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 377 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 378 | mRenders.push_back(element); |
| 379 | mActions.push_back(element); |
| 380 | } |
that | 1964d19 | 2016-01-07 00:41:03 +0100 | [diff] [blame] | 381 | else if (type == "terminal") |
| 382 | { |
| 383 | GUITerminal* element = new GUITerminal(child); |
| 384 | mObjects.push_back(element); |
| 385 | mRenders.push_back(element); |
| 386 | mActions.push_back(element); |
| 387 | mInputs.push_back(element); |
| 388 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 389 | else if (type == "button") |
| 390 | { |
| 391 | GUIButton* element = new GUIButton(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 392 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 393 | mRenders.push_back(element); |
| 394 | mActions.push_back(element); |
| 395 | } |
| 396 | else if (type == "checkbox") |
| 397 | { |
| 398 | GUICheckbox* element = new GUICheckbox(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 399 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 400 | mRenders.push_back(element); |
| 401 | mActions.push_back(element); |
| 402 | } |
| 403 | else if (type == "fileselector") |
| 404 | { |
| 405 | GUIFileSelector* element = new GUIFileSelector(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 406 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 407 | mRenders.push_back(element); |
| 408 | mActions.push_back(element); |
| 409 | } |
| 410 | else if (type == "animation") |
| 411 | { |
| 412 | GUIAnimation* element = new GUIAnimation(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 413 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 414 | mRenders.push_back(element); |
| 415 | } |
| 416 | else if (type == "progressbar") |
| 417 | { |
| 418 | GUIProgressBar* element = new GUIProgressBar(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 419 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 420 | mRenders.push_back(element); |
| 421 | mActions.push_back(element); |
| 422 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 423 | else if (type == "slider") |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 424 | { |
| 425 | GUISlider* element = new GUISlider(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 426 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 427 | mRenders.push_back(element); |
| 428 | mActions.push_back(element); |
| 429 | } |
Vojtech Bocek | 8593234 | 2013-04-01 22:11:33 +0200 | [diff] [blame] | 430 | else if (type == "slidervalue") |
| 431 | { |
| 432 | GUISliderValue *element = new GUISliderValue(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 433 | mObjects.push_back(element); |
Vojtech Bocek | 8593234 | 2013-04-01 22:11:33 +0200 | [diff] [blame] | 434 | mRenders.push_back(element); |
| 435 | mActions.push_back(element); |
| 436 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 437 | else if (type == "listbox") |
| 438 | { |
| 439 | GUIListBox* element = new GUIListBox(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 440 | mObjects.push_back(element); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 441 | mRenders.push_back(element); |
| 442 | mActions.push_back(element); |
| 443 | } |
| 444 | else if (type == "keyboard") |
| 445 | { |
| 446 | GUIKeyboard* element = new GUIKeyboard(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 447 | mObjects.push_back(element); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 448 | mRenders.push_back(element); |
| 449 | mActions.push_back(element); |
| 450 | } |
| 451 | else if (type == "input") |
| 452 | { |
| 453 | GUIInput* element = new GUIInput(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 454 | mObjects.push_back(element); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 455 | mRenders.push_back(element); |
| 456 | mActions.push_back(element); |
| 457 | mInputs.push_back(element); |
| 458 | } |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 459 | else if (type == "partitionlist") |
| 460 | { |
| 461 | GUIPartitionList* element = new GUIPartitionList(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 462 | mObjects.push_back(element); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 463 | mRenders.push_back(element); |
| 464 | mActions.push_back(element); |
| 465 | } |
Vojtech Bocek | 7e11ac5 | 2015-03-05 23:21:49 +0100 | [diff] [blame] | 466 | else if (type == "patternpassword") |
| 467 | { |
| 468 | GUIPatternPassword* element = new GUIPatternPassword(child); |
| 469 | mObjects.push_back(element); |
| 470 | mRenders.push_back(element); |
| 471 | mActions.push_back(element); |
| 472 | } |
Ethan Yonker | 44925ad | 2015-07-22 12:33:59 -0500 | [diff] [blame] | 473 | else if (type == "textbox") |
| 474 | { |
| 475 | GUITextBox* element = new GUITextBox(child); |
| 476 | mObjects.push_back(element); |
| 477 | mRenders.push_back(element); |
| 478 | mActions.push_back(element); |
| 479 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 480 | else if (type == "template") |
| 481 | { |
| 482 | if (!templates || !child->first_attribute("name")) |
| 483 | { |
| 484 | LOGERR("Invalid template request.\n"); |
| 485 | } |
| 486 | else |
| 487 | { |
| 488 | std::string name = child->first_attribute("name")->value(); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 489 | xml_node<>* node; |
| 490 | bool node_found = false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 491 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 492 | // We need to find the correct template |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 493 | for (std::vector<xml_node<>*>::iterator itr = templates->begin(); itr != templates->end(); itr++) { |
| 494 | node = (*itr)->first_node("template"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 495 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 496 | while (node) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 497 | { |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 498 | if (!node->first_attribute("name")) |
| 499 | continue; |
| 500 | |
| 501 | if (name == node->first_attribute("name")->value()) |
| 502 | { |
| 503 | if (!ProcessNode(node, templates, depth + 1)) |
| 504 | return false; |
| 505 | else { |
| 506 | node_found = true; |
| 507 | break; |
| 508 | } |
| 509 | } |
| 510 | if (node_found) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 511 | break; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 512 | node = node->next_sibling("template"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 513 | } |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 514 | // [check] why is there no if (node_found) here too? |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 515 | } |
| 516 | } |
| 517 | } |
| 518 | else |
| 519 | { |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 520 | LOGERR("Unknown object type: %s.\n", type.c_str()); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 521 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 522 | } |
| 523 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | int Page::Render(void) |
| 527 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 528 | // Render background |
| 529 | gr_color(mBackground.red, mBackground.green, mBackground.blue, mBackground.alpha); |
| 530 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 531 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 532 | // Render remaining objects |
| 533 | std::vector<RenderObject*>::iterator iter; |
| 534 | for (iter = mRenders.begin(); iter != mRenders.end(); iter++) |
| 535 | { |
| 536 | if ((*iter)->Render()) |
| 537 | LOGERR("A render request has failed.\n"); |
| 538 | } |
| 539 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | int Page::Update(void) |
| 543 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 544 | int retCode = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 545 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 546 | std::vector<RenderObject*>::iterator iter; |
| 547 | for (iter = mRenders.begin(); iter != mRenders.end(); iter++) |
| 548 | { |
| 549 | int ret = (*iter)->Update(); |
| 550 | if (ret < 0) |
| 551 | LOGERR("An update request has failed.\n"); |
| 552 | else if (ret > retCode) |
| 553 | retCode = ret; |
| 554 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 555 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 556 | return retCode; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | int Page::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 560 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 561 | // By default, return 1 to ignore further touches if nobody is listening |
| 562 | int ret = 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 563 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 564 | // Don't try to handle a lack of handlers |
| 565 | if (mActions.size() == 0) |
| 566 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 567 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 568 | // We record mTouchStart so we can pass all the touch stream to the same handler |
| 569 | if (state == TOUCH_START) |
| 570 | { |
| 571 | std::vector<ActionObject*>::reverse_iterator iter; |
| 572 | // We work backwards, from top-most element to bottom-most element |
| 573 | for (iter = mActions.rbegin(); iter != mActions.rend(); iter++) |
| 574 | { |
| 575 | if ((*iter)->IsInRegion(x, y)) |
| 576 | { |
| 577 | mTouchStart = (*iter); |
| 578 | ret = mTouchStart->NotifyTouch(state, x, y); |
| 579 | if (ret >= 0) |
| 580 | break; |
| 581 | mTouchStart = NULL; |
| 582 | } |
| 583 | } |
| 584 | } |
| 585 | else if (state == TOUCH_RELEASE && mTouchStart != NULL) |
| 586 | { |
| 587 | ret = mTouchStart->NotifyTouch(state, x, y); |
| 588 | mTouchStart = NULL; |
| 589 | } |
| 590 | else if ((state == TOUCH_DRAG || state == TOUCH_HOLD || state == TOUCH_REPEAT) && mTouchStart != NULL) |
| 591 | { |
| 592 | ret = mTouchStart->NotifyTouch(state, x, y); |
| 593 | } |
| 594 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 595 | } |
| 596 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 597 | int Page::NotifyKey(int key, bool down) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 598 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 599 | std::vector<ActionObject*>::reverse_iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 600 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 601 | int ret = 1; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 602 | // We work backwards, from top-most element to bottom-most element |
| 603 | for (iter = mActions.rbegin(); iter != mActions.rend(); iter++) |
| 604 | { |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 605 | ret = (*iter)->NotifyKey(key, down); |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 606 | if (ret == 0) |
| 607 | return 0; |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 608 | if (ret < 0) { |
| 609 | LOGERR("An action handler has returned an error\n"); |
| 610 | ret = 1; |
| 611 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 612 | } |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 613 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 614 | } |
| 615 | |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 616 | int Page::NotifyCharInput(int ch) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 617 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 618 | std::vector<InputObject*>::reverse_iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 619 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 620 | // We work backwards, from top-most element to bottom-most element |
| 621 | for (iter = mInputs.rbegin(); iter != mInputs.rend(); iter++) |
| 622 | { |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 623 | int ret = (*iter)->NotifyCharInput(ch); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 624 | if (ret == 0) |
| 625 | return 0; |
| 626 | else if (ret < 0) |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 627 | LOGERR("A char input handler has returned an error\n"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 628 | } |
| 629 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | int Page::SetKeyBoardFocus(int inFocus) |
| 633 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 634 | std::vector<InputObject*>::reverse_iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 635 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 636 | // We work backwards, from top-most element to bottom-most element |
| 637 | for (iter = mInputs.rbegin(); iter != mInputs.rend(); iter++) |
| 638 | { |
| 639 | int ret = (*iter)->SetInputFocus(inFocus); |
| 640 | if (ret == 0) |
| 641 | return 0; |
| 642 | else if (ret < 0) |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 643 | LOGERR("An input focus handler has returned an error\n"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 644 | } |
| 645 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | void Page::SetPageFocus(int inFocus) |
| 649 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 650 | // Render remaining objects |
| 651 | std::vector<RenderObject*>::iterator iter; |
| 652 | for (iter = mRenders.begin(); iter != mRenders.end(); iter++) |
| 653 | (*iter)->SetPageFocus(inFocus); |
| 654 | |
| 655 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | int Page::NotifyVarChange(std::string varName, std::string value) |
| 659 | { |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 660 | std::vector<GUIObject*>::iterator iter; |
| 661 | for (iter = mObjects.begin(); iter != mObjects.end(); ++iter) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 662 | { |
| 663 | if ((*iter)->NotifyVarChange(varName, value)) |
| 664 | LOGERR("An action handler errored on NotifyVarChange.\n"); |
| 665 | } |
| 666 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 667 | } |
| 668 | |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 669 | |
| 670 | // transient data for loading themes |
| 671 | struct LoadingContext |
| 672 | { |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 673 | ZipWrap* zip; // zip to load theme from, or NULL for the stock theme |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 674 | std::set<std::string> filenames; // to detect cyclic includes |
| 675 | std::string basepath; // if zip is NULL, base path to load includes from with trailing slash, otherwise empty |
| 676 | std::vector<xml_document<>*> xmldocs; // all loaded xml docs |
| 677 | std::vector<char*> xmlbuffers; // text buffers with xml content |
| 678 | std::vector<xml_node<>*> styles; // refer to <styles> nodes inside xmldocs |
| 679 | std::vector<xml_node<>*> templates; // refer to <templates> nodes inside xmldocs |
| 680 | |
| 681 | LoadingContext() |
| 682 | { |
| 683 | zip = NULL; |
| 684 | } |
| 685 | |
| 686 | ~LoadingContext() |
| 687 | { |
| 688 | // free all xml buffers |
| 689 | for (std::vector<char*>::iterator it = xmlbuffers.begin(); it != xmlbuffers.end(); ++it) |
| 690 | free(*it); |
| 691 | } |
| 692 | |
| 693 | }; |
| 694 | |
| 695 | // for FindStyle |
| 696 | LoadingContext* PageManager::currentLoadingContext = NULL; |
| 697 | |
| 698 | |
| 699 | PageSet::PageSet() |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 700 | { |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 701 | mResources = new ResourceManager; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 702 | mCurrentPage = NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 703 | |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 704 | set_scale_values(1, 1); // Reset any previous scaling values |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | PageSet::~PageSet() |
| 708 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 709 | mOverlays.clear(); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 710 | for (std::vector<Page*>::iterator itr = mPages.begin(); itr != mPages.end(); ++itr) |
| 711 | delete *itr; |
| 712 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 713 | delete mResources; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 714 | } |
| 715 | |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 716 | int PageSet::Load(LoadingContext& ctx, const std::string& filename) |
| 717 | { |
| 718 | bool isMain = ctx.xmlbuffers.empty(); // if we have no files yet, remember that this is the main XML file |
| 719 | |
| 720 | if (!ctx.filenames.insert(filename).second) |
| 721 | // ignore already loaded files to prevent crash with cyclic includes |
| 722 | return 0; |
| 723 | |
| 724 | // load XML into buffer |
| 725 | char* xmlbuffer = PageManager::LoadFileToBuffer(filename, ctx.zip); |
| 726 | if (!xmlbuffer) |
| 727 | return -1; // error already displayed by LoadFileToBuffer |
| 728 | ctx.xmlbuffers.push_back(xmlbuffer); |
| 729 | |
| 730 | // parse XML |
| 731 | xml_document<>* doc = new xml_document<>(); |
| 732 | doc->parse<0>(xmlbuffer); |
| 733 | ctx.xmldocs.push_back(doc); |
| 734 | |
| 735 | xml_node<>* root = doc->first_node("recovery"); |
| 736 | if (!root) |
| 737 | root = doc->first_node("install"); |
| 738 | if (!root) { |
| 739 | LOGERR("Unknown root element in %s\n", filename.c_str()); |
| 740 | return -1; |
| 741 | } |
| 742 | |
| 743 | if (isMain) { |
| 744 | int rc = LoadDetails(ctx, root); |
| 745 | if (rc != 0) |
| 746 | return rc; |
| 747 | } |
| 748 | |
| 749 | LOGINFO("Loading resources...\n"); |
| 750 | xml_node<>* child = root->first_node("resources"); |
| 751 | if (child) |
| 752 | mResources->LoadResources(child, ctx.zip, "theme"); |
| 753 | |
| 754 | LOGINFO("Loading variables...\n"); |
| 755 | child = root->first_node("variables"); |
| 756 | if (child) |
| 757 | LoadVariables(child); |
| 758 | |
| 759 | LOGINFO("Loading mouse cursor...\n"); |
| 760 | child = root->first_node("mousecursor"); |
| 761 | if (child) |
| 762 | PageManager::LoadCursorData(child); |
| 763 | |
| 764 | LOGINFO("Loading pages...\n"); |
| 765 | child = root->first_node("templates"); |
| 766 | if (child) |
| 767 | ctx.templates.push_back(child); |
| 768 | |
| 769 | child = root->first_node("styles"); |
| 770 | if (child) |
| 771 | ctx.styles.push_back(child); |
| 772 | |
| 773 | // Load pages |
| 774 | child = root->first_node("pages"); |
| 775 | if (child) { |
| 776 | if (LoadPages(ctx, child)) { |
| 777 | LOGERR("PageSet::Load returning -1\n"); |
| 778 | return -1; |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | // process includes recursively |
| 783 | child = root->first_node("include"); |
| 784 | if (child) { |
| 785 | xml_node<>* include = child->first_node("xmlfile"); |
| 786 | while (include != NULL) { |
| 787 | xml_attribute<>* attr = include->first_attribute("name"); |
| 788 | if (!attr) { |
| 789 | LOGERR("Skipping include/xmlfile with no name\n"); |
| 790 | continue; |
| 791 | } |
| 792 | |
| 793 | string filename = ctx.basepath + attr->value(); |
| 794 | LOGINFO("Including file: %s...\n", filename.c_str()); |
| 795 | int rc = Load(ctx, filename); |
| 796 | if (rc != 0) |
| 797 | return rc; |
| 798 | |
| 799 | include = include->next_sibling("xmlfile"); |
| 800 | } |
| 801 | } |
| 802 | |
| 803 | return 0; |
| 804 | } |
| 805 | |
| 806 | void PageSet::MakeEmergencyConsoleIfNeeded() |
| 807 | { |
| 808 | if (mPages.empty()) { |
| 809 | mCurrentPage = new Page(NULL, NULL); // fallback console page |
| 810 | // TODO: since removal of non-TTF fonts, the emergency console doesn't work without a font, which might be missing too |
| 811 | mPages.push_back(mCurrentPage); |
| 812 | } |
| 813 | } |
| 814 | |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 815 | int PageSet::LoadLanguage(char* languageFile, ZipWrap* package) |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 816 | { |
| 817 | xml_document<> lang; |
| 818 | xml_node<>* parent; |
| 819 | xml_node<>* child; |
| 820 | std::string resource_source; |
Ethan Yonker | 4adc33e | 2016-01-22 16:07:11 -0600 | [diff] [blame] | 821 | int ret = 0; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 822 | |
| 823 | if (languageFile) { |
| 824 | printf("parsing languageFile\n"); |
| 825 | lang.parse<0>(languageFile); |
| 826 | printf("parsing languageFile done\n"); |
| 827 | } else { |
| 828 | return -1; |
| 829 | } |
| 830 | |
| 831 | parent = lang.first_node("language"); |
| 832 | if (!parent) { |
| 833 | LOGERR("Unable to locate language node in language file.\n"); |
| 834 | lang.clear(); |
| 835 | return -1; |
| 836 | } |
| 837 | |
| 838 | child = parent->first_node("display"); |
| 839 | if (child) { |
| 840 | DataManager::SetValue("tw_language_display", child->value()); |
| 841 | resource_source = child->value(); |
| 842 | } else { |
| 843 | LOGERR("language file does not have a display value set\n"); |
| 844 | DataManager::SetValue("tw_language_display", "Not Set"); |
| 845 | resource_source = languageFile; |
| 846 | } |
| 847 | |
| 848 | child = parent->first_node("resources"); |
| 849 | if (child) |
| 850 | mResources->LoadResources(child, package, resource_source); |
| 851 | else |
Ethan Yonker | 4adc33e | 2016-01-22 16:07:11 -0600 | [diff] [blame] | 852 | ret = -1; |
| 853 | DataManager::SetValue("tw_backup_name", gui_lookup("auto_generate", "(Auto Generate)")); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 854 | lang.clear(); |
Ethan Yonker | 4adc33e | 2016-01-22 16:07:11 -0600 | [diff] [blame] | 855 | return ret; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 856 | } |
| 857 | |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 858 | int PageSet::LoadDetails(LoadingContext& ctx, xml_node<>* root) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 859 | { |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 860 | xml_node<>* child = root->first_node("details"); |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 861 | if (child) { |
Ethan Yonker | 1308d53 | 2016-01-14 22:21:49 -0600 | [diff] [blame] | 862 | int theme_ver = 0; |
| 863 | xml_node<>* themeversion = child->first_node("themeversion"); |
| 864 | if (themeversion && themeversion->value()) { |
| 865 | theme_ver = atoi(themeversion->value()); |
| 866 | } else { |
| 867 | LOGINFO("No themeversion in theme.\n"); |
| 868 | } |
| 869 | if (theme_ver != TW_THEME_VERSION) { |
| 870 | LOGINFO("theme version from xml: %i, expected %i\n", theme_ver, TW_THEME_VERSION); |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 871 | if (ctx.zip) { |
Ethan Yonker | 1308d53 | 2016-01-14 22:21:49 -0600 | [diff] [blame] | 872 | gui_err("theme_ver_err=Custom theme version does not match TWRP version. Using stock theme."); |
Ethan Yonker | 8e5692f | 2016-01-21 11:21:06 -0600 | [diff] [blame] | 873 | return TW_THEME_VER_ERR; |
Ethan Yonker | 1308d53 | 2016-01-14 22:21:49 -0600 | [diff] [blame] | 874 | } else { |
| 875 | gui_print_color("warning", "Stock theme version does not match TWRP version.\n"); |
| 876 | } |
| 877 | } |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 878 | xml_node<>* resolution = child->first_node("resolution"); |
| 879 | if (resolution) { |
Ethan Yonker | 1308d53 | 2016-01-14 22:21:49 -0600 | [diff] [blame] | 880 | LOGINFO("Checking resolution...\n"); |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 881 | xml_attribute<>* width_attr = resolution->first_attribute("width"); |
| 882 | xml_attribute<>* height_attr = resolution->first_attribute("height"); |
| 883 | xml_attribute<>* noscale_attr = resolution->first_attribute("noscaling"); |
| 884 | if (width_attr && height_attr && !noscale_attr) { |
| 885 | int width = atoi(width_attr->value()); |
| 886 | int height = atoi(height_attr->value()); |
| 887 | int offx = 0, offy = 0; |
| 888 | #ifdef TW_ROUND_SCREEN |
| 889 | xml_node<>* roundscreen = child->first_node("roundscreen"); |
| 890 | if (roundscreen) { |
| 891 | LOGINFO("TW_ROUND_SCREEN := true, using round screen XML settings.\n"); |
| 892 | xml_attribute<>* offx_attr = roundscreen->first_attribute("offset_x"); |
| 893 | xml_attribute<>* offy_attr = roundscreen->first_attribute("offset_y"); |
| 894 | if (offx_attr) { |
| 895 | offx = atoi(offx_attr->value()); |
| 896 | } |
| 897 | if (offy_attr) { |
| 898 | offy = atoi(offy_attr->value()); |
| 899 | } |
| 900 | } |
| 901 | #endif |
| 902 | if (width != 0 && height != 0) { |
James Christopher Adduono | dcd1e44 | 2016-11-06 13:17:34 -0500 | [diff] [blame] | 903 | float scale_w = (((float)gr_fb_width() + (float)tw_w_offset) - ((float)offx * 2.0)) / (float)width; |
| 904 | float scale_h = (((float)gr_fb_height() + (float)tw_h_offset) - ((float)offy * 2.0)) / (float)height; |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 905 | #ifdef TW_ROUND_SCREEN |
James Christopher Adduono | dcd1e44 | 2016-11-06 13:17:34 -0500 | [diff] [blame] | 906 | float scale_off_w = ((float)gr_fb_width() + (float)tw_w_offset) / (float)width; |
| 907 | float scale_off_h = ((float)gr_fb_height() + (float)tw_h_offset) / (float)height; |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 908 | tw_x_offset = offx * scale_off_w; |
| 909 | tw_y_offset = offy * scale_off_h; |
| 910 | #endif |
| 911 | if (scale_w != 1 || scale_h != 1) { |
James Christopher Adduono | dcd1e44 | 2016-11-06 13:17:34 -0500 | [diff] [blame] | 912 | LOGINFO("Scaling theme width %fx and height %fx, offsets x: %i y: %i w: %i h: %i\n", |
| 913 | scale_w, scale_h, tw_x_offset, tw_y_offset, tw_w_offset, tw_h_offset); |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 914 | set_scale_values(scale_w, scale_h); |
| 915 | } |
| 916 | } |
| 917 | } else { |
| 918 | LOGINFO("XML does not contain width and height, no scaling will be applied\n"); |
| 919 | } |
| 920 | } else { |
| 921 | LOGINFO("XML contains no resolution tag, no scaling will be applied.\n"); |
| 922 | } |
| 923 | } else { |
| 924 | LOGINFO("XML contains no details tag, no scaling will be applied.\n"); |
| 925 | } |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 926 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 927 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | int PageSet::SetPage(std::string page) |
| 931 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 932 | Page* tmp = FindPage(page); |
| 933 | if (tmp) |
| 934 | { |
| 935 | if (mCurrentPage) mCurrentPage->SetPageFocus(0); |
| 936 | mCurrentPage = tmp; |
| 937 | mCurrentPage->SetPageFocus(1); |
| 938 | mCurrentPage->NotifyVarChange("", ""); |
| 939 | return 0; |
| 940 | } |
| 941 | else |
| 942 | { |
| 943 | LOGERR("Unable to locate page (%s)\n", page.c_str()); |
| 944 | } |
| 945 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | int PageSet::SetOverlay(Page* page) |
| 949 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 950 | if (page) { |
| 951 | if (mOverlays.size() >= 10) { |
| 952 | LOGERR("Too many overlays requested, max is 10.\n"); |
| 953 | return -1; |
| 954 | } |
Matt Mower | d411f8d | 2015-04-09 16:04:12 -0500 | [diff] [blame] | 955 | |
| 956 | std::vector<Page*>::iterator iter; |
| 957 | for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) { |
| 958 | if ((*iter)->GetName() == page->GetName()) { |
| 959 | mOverlays.erase(iter); |
| 960 | // SetOverlay() is (and should stay) the only function which |
| 961 | // adds to mOverlays. Then, each page can appear at most once. |
| 962 | break; |
| 963 | } |
| 964 | } |
| 965 | |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 966 | page->SetPageFocus(1); |
| 967 | page->NotifyVarChange("", ""); |
| 968 | |
| 969 | if (!mOverlays.empty()) |
| 970 | mOverlays.back()->SetPageFocus(0); |
| 971 | |
| 972 | mOverlays.push_back(page); |
| 973 | } else { |
| 974 | if (!mOverlays.empty()) { |
| 975 | mOverlays.back()->SetPageFocus(0); |
| 976 | mOverlays.pop_back(); |
| 977 | if (!mOverlays.empty()) |
| 978 | mOverlays.back()->SetPageFocus(1); |
| 979 | else if (mCurrentPage) |
| 980 | mCurrentPage->SetPageFocus(1); // Just in case somehow the regular page lost focus, we'll set it again |
| 981 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 982 | } |
| 983 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 984 | } |
| 985 | |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 986 | const ResourceManager* PageSet::GetResources() |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 987 | { |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 988 | return mResources; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | Page* PageSet::FindPage(std::string name) |
| 992 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 993 | std::vector<Page*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 994 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 995 | for (iter = mPages.begin(); iter != mPages.end(); iter++) |
| 996 | { |
| 997 | if (name == (*iter)->GetName()) |
| 998 | return (*iter); |
| 999 | } |
| 1000 | return NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | int PageSet::LoadVariables(xml_node<>* vars) |
| 1004 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1005 | xml_node<>* child; |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 1006 | xml_attribute<> *name, *value, *persist; |
| 1007 | int p; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1008 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1009 | child = vars->first_node("variable"); |
| 1010 | while (child) |
| 1011 | { |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 1012 | name = child->first_attribute("name"); |
| 1013 | value = child->first_attribute("value"); |
| 1014 | persist = child->first_attribute("persist"); |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 1015 | if (name && value) |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 1016 | { |
Ethan Yonker | 751a85e | 2014-12-12 16:59:10 -0600 | [diff] [blame] | 1017 | if (strcmp(name->value(), "tw_x_offset") == 0) { |
| 1018 | tw_x_offset = atoi(value->value()); |
| 1019 | child = child->next_sibling("variable"); |
| 1020 | continue; |
| 1021 | } |
| 1022 | if (strcmp(name->value(), "tw_y_offset") == 0) { |
| 1023 | tw_y_offset = atoi(value->value()); |
| 1024 | child = child->next_sibling("variable"); |
| 1025 | continue; |
| 1026 | } |
James Christopher Adduono | dcd1e44 | 2016-11-06 13:17:34 -0500 | [diff] [blame] | 1027 | if (strcmp(name->value(), "tw_w_offset") == 0) { |
| 1028 | tw_w_offset = atoi(value->value()); |
| 1029 | child = child->next_sibling("variable"); |
| 1030 | continue; |
| 1031 | } |
| 1032 | if (strcmp(name->value(), "tw_h_offset") == 0) { |
| 1033 | tw_h_offset = atoi(value->value()); |
| 1034 | child = child->next_sibling("variable"); |
| 1035 | continue; |
| 1036 | } |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 1037 | p = persist ? atoi(persist->value()) : 0; |
Ethan Yonker | 96acb3d | 2014-08-05 09:20:30 -0500 | [diff] [blame] | 1038 | string temp = value->value(); |
| 1039 | string valstr = gui_parse_text(temp); |
| 1040 | |
| 1041 | if (valstr.find("+") != string::npos) { |
| 1042 | string val1str = valstr; |
| 1043 | val1str = val1str.substr(0, val1str.find('+')); |
| 1044 | string val2str = valstr; |
| 1045 | val2str = val2str.substr(val2str.find('+') + 1, string::npos); |
| 1046 | int val1 = atoi(val1str.c_str()); |
| 1047 | int val2 = atoi(val2str.c_str()); |
| 1048 | int val = val1 + val2; |
| 1049 | |
| 1050 | DataManager::SetValue(name->value(), val, p); |
| 1051 | } else if (valstr.find("-") != string::npos) { |
| 1052 | string val1str = valstr; |
| 1053 | val1str = val1str.substr(0, val1str.find('-')); |
| 1054 | string val2str = valstr; |
| 1055 | val2str = val2str.substr(val2str.find('-') + 1, string::npos); |
| 1056 | int val1 = atoi(val1str.c_str()); |
| 1057 | int val2 = atoi(val2str.c_str()); |
| 1058 | int val = val1 - val2; |
| 1059 | |
| 1060 | DataManager::SetValue(name->value(), val, p); |
| 1061 | } else { |
| 1062 | DataManager::SetValue(name->value(), valstr, p); |
| 1063 | } |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 1064 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1065 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1066 | child = child->next_sibling("variable"); |
| 1067 | } |
| 1068 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1069 | } |
| 1070 | |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 1071 | int PageSet::LoadPages(LoadingContext& ctx, xml_node<>* pages) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1072 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1073 | xml_node<>* child; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1074 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1075 | if (!pages) |
| 1076 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1077 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1078 | child = pages->first_node("page"); |
| 1079 | while (child != NULL) |
| 1080 | { |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 1081 | Page* page = new Page(child, &ctx.templates); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1082 | if (page->GetName().empty()) |
| 1083 | { |
| 1084 | LOGERR("Unable to process load page\n"); |
| 1085 | delete page; |
| 1086 | } |
| 1087 | else |
| 1088 | { |
| 1089 | mPages.push_back(page); |
| 1090 | } |
| 1091 | child = child->next_sibling("page"); |
| 1092 | } |
| 1093 | if (mPages.size() > 0) |
| 1094 | return 0; |
| 1095 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | int PageSet::IsCurrentPage(Page* page) |
| 1099 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1100 | return ((mCurrentPage && mCurrentPage == page) ? 1 : 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1101 | } |
| 1102 | |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 1103 | std::string PageSet::GetCurrentPage() const |
| 1104 | { |
| 1105 | return mCurrentPage ? mCurrentPage->GetName() : ""; |
| 1106 | } |
| 1107 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1108 | int PageSet::Render(void) |
| 1109 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1110 | int ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1111 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1112 | ret = (mCurrentPage ? mCurrentPage->Render() : -1); |
| 1113 | if (ret < 0) |
| 1114 | return ret; |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1115 | |
| 1116 | std::vector<Page*>::iterator iter; |
| 1117 | |
| 1118 | for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) { |
| 1119 | ret = ((*iter) ? (*iter)->Render() : -1); |
| 1120 | if (ret < 0) |
| 1121 | return ret; |
| 1122 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1123 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | int PageSet::Update(void) |
| 1127 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1128 | int ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1129 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1130 | ret = (mCurrentPage ? mCurrentPage->Update() : -1); |
| 1131 | if (ret < 0 || ret > 1) |
| 1132 | return ret; |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1133 | |
| 1134 | std::vector<Page*>::iterator iter; |
| 1135 | |
| 1136 | for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) { |
| 1137 | ret = ((*iter) ? (*iter)->Update() : -1); |
| 1138 | if (ret < 0) |
| 1139 | return ret; |
| 1140 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1141 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | int PageSet::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 1145 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1146 | if (!mOverlays.empty()) |
| 1147 | return mOverlays.back()->NotifyTouch(state, x, y); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1148 | |
| 1149 | return (mCurrentPage ? mCurrentPage->NotifyTouch(state, x, y) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1150 | } |
| 1151 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1152 | int PageSet::NotifyKey(int key, bool down) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1153 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1154 | if (!mOverlays.empty()) |
| 1155 | return mOverlays.back()->NotifyKey(key, down); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1156 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1157 | return (mCurrentPage ? mCurrentPage->NotifyKey(key, down) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1158 | } |
| 1159 | |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 1160 | int PageSet::NotifyCharInput(int ch) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1161 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1162 | if (!mOverlays.empty()) |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 1163 | return mOverlays.back()->NotifyCharInput(ch); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1164 | |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 1165 | return (mCurrentPage ? mCurrentPage->NotifyCharInput(ch) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1166 | } |
| 1167 | |
| 1168 | int PageSet::SetKeyBoardFocus(int inFocus) |
| 1169 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1170 | if (!mOverlays.empty()) |
| 1171 | return mOverlays.back()->SetKeyBoardFocus(inFocus); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1172 | |
| 1173 | return (mCurrentPage ? mCurrentPage->SetKeyBoardFocus(inFocus) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | int PageSet::NotifyVarChange(std::string varName, std::string value) |
| 1177 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1178 | std::vector<Page*>::iterator iter; |
| 1179 | |
| 1180 | for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) |
| 1181 | (*iter)->NotifyVarChange(varName, value); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1182 | |
| 1183 | return (mCurrentPage ? mCurrentPage->NotifyVarChange(varName, value) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1184 | } |
| 1185 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1186 | void PageSet::AddStringResource(std::string resource_source, std::string resource_name, std::string value) |
| 1187 | { |
| 1188 | mResources->AddStringResource(resource_source, resource_name, value); |
| 1189 | } |
| 1190 | |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 1191 | char* PageManager::LoadFileToBuffer(std::string filename, ZipWrap* package) { |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1192 | size_t len; |
| 1193 | char* buffer = NULL; |
| 1194 | |
| 1195 | if (!package) { |
| 1196 | // We can try to load the XML directly... |
| 1197 | LOGINFO("PageManager::LoadFileToBuffer loading filename: '%s' directly\n", filename.c_str()); |
| 1198 | struct stat st; |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 1199 | if (stat(filename.c_str(),&st) != 0) { |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1200 | // This isn't always an error, sometimes we request files that don't exist. |
| 1201 | return NULL; |
| 1202 | } |
| 1203 | |
| 1204 | len = (size_t)st.st_size; |
| 1205 | |
| 1206 | buffer = (char*) malloc(len + 1); |
| 1207 | if (!buffer) { |
| 1208 | LOGERR("PageManager::LoadFileToBuffer failed to malloc\n"); |
| 1209 | return NULL; |
| 1210 | } |
| 1211 | |
| 1212 | int fd = open(filename.c_str(), O_RDONLY); |
| 1213 | if (fd == -1) { |
| 1214 | LOGERR("PageManager::LoadFileToBuffer failed to open '%s' - (%s)\n", filename.c_str(), strerror(errno)); |
| 1215 | free(buffer); |
| 1216 | return NULL; |
| 1217 | } |
| 1218 | |
| 1219 | if (read(fd, buffer, len) < 0) { |
| 1220 | LOGERR("PageManager::LoadFileToBuffer failed to read '%s' - (%s)\n", filename.c_str(), strerror(errno)); |
| 1221 | free(buffer); |
| 1222 | close(fd); |
| 1223 | return NULL; |
| 1224 | } |
| 1225 | close(fd); |
| 1226 | } else { |
| 1227 | LOGINFO("PageManager::LoadFileToBuffer loading filename: '%s' from zip\n", filename.c_str()); |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 1228 | if (!package->EntryExists(filename)) { |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1229 | LOGERR("Unable to locate '%s' in zip file\n", filename.c_str()); |
| 1230 | return NULL; |
| 1231 | } |
| 1232 | |
| 1233 | // Allocate the buffer for the file |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 1234 | len = package->GetUncompressedSize(filename); |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1235 | buffer = (char*) malloc(len + 1); |
| 1236 | if (!buffer) |
| 1237 | return NULL; |
| 1238 | |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 1239 | if (!package->ExtractToBuffer(filename, (unsigned char*) buffer)) { |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1240 | LOGERR("Unable to extract '%s'\n", filename.c_str()); |
| 1241 | free(buffer); |
| 1242 | return NULL; |
| 1243 | } |
| 1244 | } |
| 1245 | // NULL-terminate the string |
| 1246 | buffer[len] = 0x00; |
| 1247 | return buffer; |
| 1248 | } |
| 1249 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1250 | void PageManager::LoadLanguageListDir(string dir) { |
| 1251 | if (!TWFunc::Path_Exists(dir)) { |
| 1252 | LOGERR("LoadLanguageListDir '%s' path not found\n", dir.c_str()); |
| 1253 | return; |
| 1254 | } |
| 1255 | |
| 1256 | DIR *d = opendir(dir.c_str()); |
| 1257 | struct dirent *p; |
| 1258 | |
| 1259 | if (d == NULL) { |
| 1260 | LOGERR("LoadLanguageListDir error opening dir: '%s', %s\n", dir.c_str(), strerror(errno)); |
| 1261 | return; |
| 1262 | } |
| 1263 | |
| 1264 | while ((p = readdir(d))) { |
| 1265 | if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, "..") || strlen(p->d_name) < 5) |
| 1266 | continue; |
| 1267 | |
| 1268 | string file = p->d_name; |
| 1269 | if (file.substr(strlen(p->d_name) - 4) != ".xml") |
| 1270 | continue; |
| 1271 | string path = dir + p->d_name; |
| 1272 | string file_no_extn = file.substr(0, strlen(p->d_name) - 4); |
| 1273 | struct language_struct language_entry; |
| 1274 | language_entry.filename = file_no_extn; |
| 1275 | char* xmlFile = PageManager::LoadFileToBuffer(dir + p->d_name, NULL); |
| 1276 | if (xmlFile == NULL) { |
| 1277 | LOGERR("LoadLanguageListDir unable to load '%s'\n", language_entry.filename.c_str()); |
| 1278 | continue; |
| 1279 | } |
| 1280 | xml_document<> *doc = new xml_document<>(); |
| 1281 | doc->parse<0>(xmlFile); |
| 1282 | |
| 1283 | xml_node<>* parent = doc->first_node("language"); |
| 1284 | if (!parent) { |
| 1285 | LOGERR("Invalid language XML file '%s'\n", language_entry.filename.c_str()); |
| 1286 | } else { |
| 1287 | xml_node<>* child = parent->first_node("display"); |
| 1288 | if (child) { |
| 1289 | language_entry.displayvalue = child->value(); |
| 1290 | } else { |
| 1291 | LOGERR("No display value for '%s'\n", language_entry.filename.c_str()); |
| 1292 | language_entry.displayvalue = language_entry.filename; |
| 1293 | } |
| 1294 | Language_List.push_back(language_entry); |
| 1295 | } |
| 1296 | doc->clear(); |
| 1297 | delete doc; |
| 1298 | free(xmlFile); |
| 1299 | } |
| 1300 | closedir(d); |
| 1301 | } |
| 1302 | |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 1303 | void PageManager::LoadLanguageList(ZipWrap* package) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1304 | Language_List.clear(); |
| 1305 | if (TWFunc::Path_Exists(TWRES "customlanguages")) |
| 1306 | TWFunc::removeDir(TWRES "customlanguages", true); |
| 1307 | if (package) { |
| 1308 | TWFunc::Recursive_Mkdir(TWRES "customlanguages"); |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 1309 | package->ExtractRecursive("languages", TWRES "customlanguages/"); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1310 | LoadLanguageListDir(TWRES "customlanguages/"); |
| 1311 | } else { |
| 1312 | LoadLanguageListDir(TWRES "languages/"); |
| 1313 | } |
Xuefer | cac6ace | 2016-02-01 02:28:55 +0800 | [diff] [blame] | 1314 | |
| 1315 | std::sort(Language_List.begin(), Language_List.end()); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | void PageManager::LoadLanguage(string filename) { |
| 1319 | string actual_filename; |
| 1320 | if (TWFunc::Path_Exists(TWRES "customlanguages/" + filename + ".xml")) |
| 1321 | actual_filename = TWRES "customlanguages/" + filename + ".xml"; |
| 1322 | else |
| 1323 | actual_filename = TWRES "languages/" + filename + ".xml"; |
| 1324 | char* xmlFile = PageManager::LoadFileToBuffer(actual_filename, NULL); |
| 1325 | if (xmlFile == NULL) |
| 1326 | LOGERR("Unable to load '%s'\n", actual_filename.c_str()); |
| 1327 | else { |
| 1328 | mCurrentSet->LoadLanguage(xmlFile, NULL); |
| 1329 | free(xmlFile); |
| 1330 | } |
| 1331 | PartitionManager.Translate_Partition_Display_Names(); |
| 1332 | } |
| 1333 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1334 | int PageManager::LoadPackage(std::string name, std::string package, std::string startpage) |
| 1335 | { |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 1336 | std::string mainxmlfilename = package; |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 1337 | ZipWrap zip; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1338 | char* languageFile = NULL; |
Ethan Yonker | 8e5692f | 2016-01-21 11:21:06 -0600 | [diff] [blame] | 1339 | char* baseLanguageFile = NULL; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1340 | PageSet* pageSet = NULL; |
| 1341 | int ret; |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1342 | MemMapping map; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1343 | |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 1344 | mReloadTheme = false; |
| 1345 | mStartPage = startpage; |
| 1346 | |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 1347 | // init the loading context |
| 1348 | LoadingContext ctx; |
| 1349 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1350 | // Open the XML file |
| 1351 | LOGINFO("Loading package: %s (%s)\n", name.c_str(), package.c_str()); |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1352 | if (package.size() > 4 && package.substr(package.size() - 4) != ".zip") |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1353 | { |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1354 | LOGINFO("Load XML directly\n"); |
Ethan Yonker | 751a85e | 2014-12-12 16:59:10 -0600 | [diff] [blame] | 1355 | tw_x_offset = TW_X_OFFSET; |
| 1356 | tw_y_offset = TW_Y_OFFSET; |
James Christopher Adduono | dcd1e44 | 2016-11-06 13:17:34 -0500 | [diff] [blame] | 1357 | tw_w_offset = TW_W_OFFSET; |
| 1358 | tw_h_offset = TW_H_OFFSET; |
Ethan Yonker | 4f74d14 | 2016-03-31 08:10:37 -0500 | [diff] [blame] | 1359 | if (name != "splash") { |
| 1360 | LoadLanguageList(NULL); |
| 1361 | languageFile = LoadFileToBuffer(TWRES "languages/en.xml", NULL); |
| 1362 | } |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 1363 | ctx.basepath = TWRES; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1364 | } |
| 1365 | else |
| 1366 | { |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1367 | LOGINFO("Loading zip theme\n"); |
Ethan Yonker | 751a85e | 2014-12-12 16:59:10 -0600 | [diff] [blame] | 1368 | tw_x_offset = 0; |
| 1369 | tw_y_offset = 0; |
James Christopher Adduono | dcd1e44 | 2016-11-06 13:17:34 -0500 | [diff] [blame] | 1370 | tw_w_offset = 0; |
| 1371 | tw_h_offset = 0; |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1372 | if (!TWFunc::Path_Exists(package)) |
| 1373 | return -1; |
Ethan Yonker | ecbd3e8 | 2017-12-14 14:43:59 -0600 | [diff] [blame] | 1374 | #ifdef USE_MINZIP |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1375 | if (sysMapFile(package.c_str(), &map) != 0) { |
Ethan Yonker | ecbd3e8 | 2017-12-14 14:43:59 -0600 | [diff] [blame] | 1376 | #else |
| 1377 | if (!map.MapFile(package)) { |
| 1378 | #endif |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1379 | LOGERR("Failed to map '%s'\n", package.c_str()); |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1380 | goto error; |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1381 | } |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 1382 | if (!zip.Open(package.c_str(), &map)) { |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1383 | LOGERR("Unable to open zip archive '%s'\n", package.c_str()); |
Ethan Yonker | ecbd3e8 | 2017-12-14 14:43:59 -0600 | [diff] [blame] | 1384 | #ifdef USE_MINZIP |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1385 | sysReleaseMap(&map); |
Ethan Yonker | ecbd3e8 | 2017-12-14 14:43:59 -0600 | [diff] [blame] | 1386 | #endif |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1387 | goto error; |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1388 | } |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 1389 | ctx.zip = &zip; |
| 1390 | mainxmlfilename = "ui.xml"; |
| 1391 | LoadLanguageList(ctx.zip); |
| 1392 | languageFile = LoadFileToBuffer("languages/en.xml", ctx.zip); |
Ethan Yonker | 8e5692f | 2016-01-21 11:21:06 -0600 | [diff] [blame] | 1393 | baseLanguageFile = LoadFileToBuffer(TWRES "languages/en.xml", NULL); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1394 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1395 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1396 | // Before loading, mCurrentSet must be the loading package so we can find resources |
| 1397 | pageSet = mCurrentSet; |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 1398 | mCurrentSet = new PageSet(); |
| 1399 | |
| 1400 | if (baseLanguageFile) { |
| 1401 | mCurrentSet->LoadLanguage(baseLanguageFile, NULL); |
| 1402 | free(baseLanguageFile); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1403 | } |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 1404 | |
| 1405 | if (languageFile) { |
| 1406 | mCurrentSet->LoadLanguage(languageFile, ctx.zip); |
| 1407 | free(languageFile); |
| 1408 | } |
| 1409 | |
| 1410 | // Load and parse the XML and all includes |
| 1411 | currentLoadingContext = &ctx; // required to find styles |
| 1412 | ret = mCurrentSet->Load(ctx, mainxmlfilename); |
| 1413 | currentLoadingContext = NULL; |
| 1414 | |
Ethan Yonker | 8e5692f | 2016-01-21 11:21:06 -0600 | [diff] [blame] | 1415 | if (ret == 0) { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1416 | mCurrentSet->SetPage(startpage); |
| 1417 | mPageSets.insert(std::pair<std::string, PageSet*>(name, mCurrentSet)); |
Ethan Yonker | 8e5692f | 2016-01-21 11:21:06 -0600 | [diff] [blame] | 1418 | } else { |
| 1419 | if (ret != TW_THEME_VER_ERR) |
| 1420 | LOGERR("Package %s failed to load.\n", name.c_str()); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1421 | } |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 1422 | |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 1423 | // reset to previous pageset |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1424 | mCurrentSet = pageSet; |
| 1425 | |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 1426 | if (ctx.zip) { |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 1427 | ctx.zip->Close(); |
Ethan Yonker | ecbd3e8 | 2017-12-14 14:43:59 -0600 | [diff] [blame] | 1428 | #ifdef USE_MINZIP |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1429 | sysReleaseMap(&map); |
Ethan Yonker | ecbd3e8 | 2017-12-14 14:43:59 -0600 | [diff] [blame] | 1430 | #endif |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1431 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1432 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1433 | |
| 1434 | error: |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1435 | // Sometimes we get here without a real error |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 1436 | if (ctx.zip) { |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 1437 | ctx.zip->Close(); |
Ethan Yonker | ecbd3e8 | 2017-12-14 14:43:59 -0600 | [diff] [blame] | 1438 | #ifdef USE_MINZIP |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1439 | sysReleaseMap(&map); |
Ethan Yonker | ecbd3e8 | 2017-12-14 14:43:59 -0600 | [diff] [blame] | 1440 | #endif |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1441 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1442 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1443 | } |
| 1444 | |
| 1445 | PageSet* PageManager::FindPackage(std::string name) |
| 1446 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1447 | std::map<std::string, PageSet*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1448 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1449 | iter = mPageSets.find(name); |
| 1450 | if (iter != mPageSets.end()) |
| 1451 | return (*iter).second; |
| 1452 | |
| 1453 | LOGERR("Unable to locate package %s\n", name.c_str()); |
| 1454 | return NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | PageSet* PageManager::SelectPackage(std::string name) |
| 1458 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1459 | LOGINFO("Switching packages (%s)\n", name.c_str()); |
| 1460 | PageSet* tmp; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1461 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1462 | tmp = FindPackage(name); |
| 1463 | if (tmp) |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 1464 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1465 | mCurrentSet = tmp; |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 1466 | mCurrentSet->MakeEmergencyConsoleIfNeeded(); |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 1467 | mCurrentSet->NotifyVarChange("", ""); |
| 1468 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1469 | else |
| 1470 | LOGERR("Unable to find package.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1471 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1472 | return mCurrentSet; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1473 | } |
| 1474 | |
| 1475 | int PageManager::ReloadPackage(std::string name, std::string package) |
| 1476 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1477 | std::map<std::string, PageSet*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1478 | |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 1479 | mReloadTheme = false; |
| 1480 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1481 | iter = mPageSets.find(name); |
| 1482 | if (iter == mPageSets.end()) |
| 1483 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1484 | |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 1485 | if (mMouseCursor) |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1486 | mMouseCursor->ResetData(gr_fb_width(), gr_fb_height()); |
| 1487 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1488 | PageSet* set = (*iter).second; |
| 1489 | mPageSets.erase(iter); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1490 | |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 1491 | if (LoadPackage(name, package, mStartPage) != 0) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1492 | { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1493 | LOGINFO("Failed to load package '%s'.\n", package.c_str()); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1494 | mPageSets.insert(std::pair<std::string, PageSet*>(name, set)); |
| 1495 | return -1; |
| 1496 | } |
| 1497 | if (mCurrentSet == set) |
| 1498 | SelectPackage(name); |
| 1499 | delete set; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1500 | GUIConsole::Translate_Now(); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1501 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | void PageManager::ReleasePackage(std::string name) |
| 1505 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1506 | std::map<std::string, PageSet*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1507 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1508 | iter = mPageSets.find(name); |
| 1509 | if (iter == mPageSets.end()) |
| 1510 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1511 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1512 | PageSet* set = (*iter).second; |
| 1513 | mPageSets.erase(iter); |
| 1514 | delete set; |
that | 235c648 | 2016-01-24 21:59:00 +0100 | [diff] [blame] | 1515 | if (set == mCurrentSet) |
| 1516 | mCurrentSet = NULL; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1517 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1518 | } |
| 1519 | |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 1520 | int PageManager::RunReload() { |
| 1521 | int ret_val = 0; |
| 1522 | std::string theme_path; |
| 1523 | |
| 1524 | if (!mReloadTheme) |
| 1525 | return 0; |
| 1526 | |
| 1527 | mReloadTheme = false; |
| 1528 | theme_path = DataManager::GetSettingsStoragePath(); |
| 1529 | if (PartitionManager.Mount_By_Path(theme_path.c_str(), 1) < 0) { |
| 1530 | LOGERR("Unable to mount %s during gui_reload_theme function.\n", theme_path.c_str()); |
| 1531 | ret_val = 1; |
| 1532 | } |
| 1533 | |
| 1534 | theme_path += "/TWRP/theme/ui.zip"; |
| 1535 | if (ret_val != 0 || ReloadPackage("TWRP", theme_path) != 0) |
| 1536 | { |
| 1537 | // Loading the custom theme failed - try loading the stock theme |
| 1538 | LOGINFO("Attempting to reload stock theme...\n"); |
| 1539 | if (ReloadPackage("TWRP", TWRES "ui.xml")) |
| 1540 | { |
| 1541 | LOGERR("Failed to load base packages.\n"); |
| 1542 | ret_val = 1; |
| 1543 | } |
| 1544 | } |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1545 | if (ret_val == 0) { |
| 1546 | if (DataManager::GetStrValue("tw_language") != "en.xml") { |
| 1547 | LOGINFO("Loading language '%s'\n", DataManager::GetStrValue("tw_language").c_str()); |
| 1548 | LoadLanguage(DataManager::GetStrValue("tw_language")); |
| 1549 | } |
| 1550 | } |
| 1551 | |
| 1552 | // This makes the console re-translate |
that | a9dd9f0 | 2017-02-23 23:08:56 +0100 | [diff] [blame] | 1553 | GUIConsole::Clear_For_Retranslation(); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1554 | |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 1555 | return ret_val; |
| 1556 | } |
| 1557 | |
| 1558 | void PageManager::RequestReload() { |
| 1559 | mReloadTheme = true; |
| 1560 | } |
| 1561 | |
Ethan Yonker | afde098 | 2016-01-23 08:55:35 -0600 | [diff] [blame] | 1562 | void PageManager::SetStartPage(const std::string& page_name) { |
| 1563 | mStartPage = page_name; |
| 1564 | } |
| 1565 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1566 | int PageManager::ChangePage(std::string name) |
| 1567 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1568 | DataManager::SetValue("tw_operation_state", 0); |
| 1569 | int ret = (mCurrentSet ? mCurrentSet->SetPage(name) : -1); |
| 1570 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1571 | } |
| 1572 | |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 1573 | std::string PageManager::GetCurrentPage() |
| 1574 | { |
| 1575 | return mCurrentSet ? mCurrentSet->GetCurrentPage() : ""; |
| 1576 | } |
| 1577 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1578 | int PageManager::ChangeOverlay(std::string name) |
| 1579 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1580 | if (name.empty()) |
| 1581 | return mCurrentSet->SetOverlay(NULL); |
| 1582 | else |
| 1583 | { |
Ethan Yonker | 1308d53 | 2016-01-14 22:21:49 -0600 | [diff] [blame] | 1584 | Page* page = mCurrentSet ? mCurrentSet->FindPage(name) : NULL; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1585 | return mCurrentSet->SetOverlay(page); |
| 1586 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1587 | } |
| 1588 | |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 1589 | const ResourceManager* PageManager::GetResources() |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1590 | { |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 1591 | return (mCurrentSet ? mCurrentSet->GetResources() : NULL); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1592 | } |
| 1593 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1594 | int PageManager::IsCurrentPage(Page* page) |
| 1595 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1596 | return (mCurrentSet ? mCurrentSet->IsCurrentPage(page) : 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | int PageManager::Render(void) |
| 1600 | { |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 1601 | if (blankTimer.isScreenOff()) |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 1602 | return 0; |
| 1603 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1604 | int res = (mCurrentSet ? mCurrentSet->Render() : -1); |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 1605 | if (mMouseCursor) |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1606 | mMouseCursor->Render(); |
| 1607 | return res; |
| 1608 | } |
| 1609 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1610 | HardwareKeyboard *PageManager::GetHardwareKeyboard() |
| 1611 | { |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 1612 | if (!mHardwareKeyboard) |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1613 | mHardwareKeyboard = new HardwareKeyboard(); |
| 1614 | return mHardwareKeyboard; |
| 1615 | } |
| 1616 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 1617 | xml_node<>* PageManager::FindStyle(std::string name) |
| 1618 | { |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 1619 | if (!currentLoadingContext) |
| 1620 | { |
| 1621 | LOGERR("FindStyle works only while loading a theme.\n"); |
| 1622 | return NULL; |
| 1623 | } |
| 1624 | |
| 1625 | for (std::vector<xml_node<>*>::iterator itr = currentLoadingContext->styles.begin(); itr != currentLoadingContext->styles.end(); itr++) { |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 1626 | xml_node<>* node = (*itr)->first_node("style"); |
| 1627 | |
| 1628 | while (node) { |
| 1629 | if (!node->first_attribute("name")) |
| 1630 | continue; |
| 1631 | |
| 1632 | if (name == node->first_attribute("name")->value()) |
| 1633 | return node; |
| 1634 | node = node->next_sibling("style"); |
| 1635 | } |
| 1636 | } |
| 1637 | return NULL; |
| 1638 | } |
| 1639 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1640 | MouseCursor *PageManager::GetMouseCursor() |
| 1641 | { |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 1642 | if (!mMouseCursor) |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1643 | mMouseCursor = new MouseCursor(gr_fb_width(), gr_fb_height()); |
| 1644 | return mMouseCursor; |
| 1645 | } |
| 1646 | |
| 1647 | void PageManager::LoadCursorData(xml_node<>* node) |
| 1648 | { |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 1649 | if (!mMouseCursor) |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1650 | mMouseCursor = new MouseCursor(gr_fb_width(), gr_fb_height()); |
| 1651 | |
| 1652 | mMouseCursor->LoadData(node); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1653 | } |
| 1654 | |
| 1655 | int PageManager::Update(void) |
| 1656 | { |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 1657 | if (blankTimer.isScreenOff()) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1658 | return 0; |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1659 | |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 1660 | if (RunReload()) |
| 1661 | return -2; |
| 1662 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1663 | int res = (mCurrentSet ? mCurrentSet->Update() : -1); |
| 1664 | |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 1665 | if (mMouseCursor) |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1666 | { |
| 1667 | int c_res = mMouseCursor->Update(); |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 1668 | if (c_res > res) |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1669 | res = c_res; |
| 1670 | } |
| 1671 | return res; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1672 | } |
| 1673 | |
| 1674 | int PageManager::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 1675 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1676 | return (mCurrentSet ? mCurrentSet->NotifyTouch(state, x, y) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1677 | } |
| 1678 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1679 | int PageManager::NotifyKey(int key, bool down) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1680 | { |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1681 | return (mCurrentSet ? mCurrentSet->NotifyKey(key, down) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1682 | } |
| 1683 | |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 1684 | int PageManager::NotifyCharInput(int ch) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1685 | { |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 1686 | return (mCurrentSet ? mCurrentSet->NotifyCharInput(ch) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | int PageManager::SetKeyBoardFocus(int inFocus) |
| 1690 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1691 | return (mCurrentSet ? mCurrentSet->SetKeyBoardFocus(inFocus) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1692 | } |
| 1693 | |
| 1694 | int PageManager::NotifyVarChange(std::string varName, std::string value) |
| 1695 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1696 | return (mCurrentSet ? mCurrentSet->NotifyVarChange(varName, value) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1697 | } |
| 1698 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1699 | void PageManager::AddStringResource(std::string resource_source, std::string resource_name, std::string value) |
| 1700 | { |
| 1701 | if (mCurrentSet) |
| 1702 | mCurrentSet->AddStringResource(resource_source, resource_name, value); |
| 1703 | } |
| 1704 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1705 | extern "C" void gui_notifyVarChange(const char *name, const char* value) |
| 1706 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1707 | if (!gGuiRunning) |
| 1708 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1709 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1710 | PageManager::NotifyVarChange(name, value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1711 | } |