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