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