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