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