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 | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 35 | #include "../twrp-functions.hpp" |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 36 | #include "../partitions.hpp" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 37 | |
| 38 | #include <string> |
| 39 | |
| 40 | extern "C" { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 41 | #include "../twcommon.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 42 | #include "../minuitwrp/minui.h" |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 43 | #include "../minzip/SysUtil.h" |
| 44 | #include "../minzip/Zip.h" |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 45 | #include "gui.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | #include "rapidxml.hpp" |
| 49 | #include "objects.hpp" |
gordon1337 | 0d9133d | 2013-06-08 14:17:07 +0200 | [diff] [blame] | 50 | #include "blanktimer.hpp" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 51 | |
Ethan Yonker | 1308d53 | 2016-01-14 22:21:49 -0600 | [diff] [blame] | 52 | #define TW_THEME_VERSION 1 |
Ethan Yonker | 8e5692f | 2016-01-21 11:21:06 -0600 | [diff] [blame] | 53 | #define TW_THEME_VER_ERR -2 |
Ethan Yonker | 1308d53 | 2016-01-14 22:21:49 -0600 | [diff] [blame] | 54 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 55 | extern int gGuiRunning; |
| 56 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 57 | // From ../twrp.cpp |
| 58 | extern bool datamedia; |
| 59 | |
| 60 | // From console.cpp |
| 61 | extern size_t last_message_count; |
| 62 | extern std::vector<std::string> gConsole; |
| 63 | extern std::vector<std::string> gConsoleColor; |
| 64 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 65 | std::map<std::string, PageSet*> PageManager::mPageSets; |
| 66 | PageSet* PageManager::mCurrentSet; |
| 67 | PageSet* PageManager::mBaseSet = NULL; |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 68 | MouseCursor *PageManager::mMouseCursor = NULL; |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 69 | HardwareKeyboard *PageManager::mHardwareKeyboard = NULL; |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 70 | bool PageManager::mReloadTheme = false; |
| 71 | std::string PageManager::mStartPage = "main"; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 72 | std::vector<language_struct> Language_List; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 73 | |
Ethan Yonker | 751a85e | 2014-12-12 16:59:10 -0600 | [diff] [blame] | 74 | int tw_x_offset = 0; |
| 75 | int tw_y_offset = 0; |
| 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 | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 624 | LOGERR("A char input handler has returned an error"); |
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) |
| 640 | LOGERR("An input focus handler has returned an error"); |
| 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 | |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 666 | PageSet::PageSet(const char* xmlFile) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 667 | { |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 668 | mResources = new ResourceManager; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 669 | mCurrentPage = NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 670 | |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 671 | if (!xmlFile) |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 672 | mCurrentPage = new Page(NULL, NULL); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | PageSet::~PageSet() |
| 676 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 677 | mOverlays.clear(); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 678 | for (std::vector<Page*>::iterator itr = mPages.begin(); itr != mPages.end(); ++itr) |
| 679 | delete *itr; |
| 680 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 681 | delete mResources; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 682 | } |
| 683 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 684 | int PageSet::LoadLanguage(char* languageFile, ZipArchive* package) |
| 685 | { |
| 686 | xml_document<> lang; |
| 687 | xml_node<>* parent; |
| 688 | xml_node<>* child; |
| 689 | std::string resource_source; |
Ethan Yonker | 4adc33e | 2016-01-22 16:07:11 -0600 | [diff] [blame^] | 690 | int ret = 0; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 691 | |
| 692 | if (languageFile) { |
| 693 | printf("parsing languageFile\n"); |
| 694 | lang.parse<0>(languageFile); |
| 695 | printf("parsing languageFile done\n"); |
| 696 | } else { |
| 697 | return -1; |
| 698 | } |
| 699 | |
| 700 | parent = lang.first_node("language"); |
| 701 | if (!parent) { |
| 702 | LOGERR("Unable to locate language node in language file.\n"); |
| 703 | lang.clear(); |
| 704 | return -1; |
| 705 | } |
| 706 | |
| 707 | child = parent->first_node("display"); |
| 708 | if (child) { |
| 709 | DataManager::SetValue("tw_language_display", child->value()); |
| 710 | resource_source = child->value(); |
| 711 | } else { |
| 712 | LOGERR("language file does not have a display value set\n"); |
| 713 | DataManager::SetValue("tw_language_display", "Not Set"); |
| 714 | resource_source = languageFile; |
| 715 | } |
| 716 | |
| 717 | child = parent->first_node("resources"); |
| 718 | if (child) |
| 719 | mResources->LoadResources(child, package, resource_source); |
| 720 | else |
Ethan Yonker | 4adc33e | 2016-01-22 16:07:11 -0600 | [diff] [blame^] | 721 | ret = -1; |
| 722 | DataManager::SetValue("tw_backup_name", gui_lookup("auto_generate", "(Auto Generate)")); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 723 | lang.clear(); |
Ethan Yonker | 4adc33e | 2016-01-22 16:07:11 -0600 | [diff] [blame^] | 724 | return ret; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 725 | } |
| 726 | |
Ethan Yonker | 8e5692f | 2016-01-21 11:21:06 -0600 | [diff] [blame] | 727 | int PageSet::Load(ZipArchive* package, char* xmlFile, char* languageFile, char* baseLanguageFile) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 728 | { |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 729 | xml_document<> mDoc; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 730 | xml_node<>* parent; |
| 731 | xml_node<>* child; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 732 | xml_node<>* xmltemplate; |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 733 | xml_node<>* xmlstyle; |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 734 | |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 735 | mDoc.parse<0>(xmlFile); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 736 | parent = mDoc.first_node("recovery"); |
| 737 | if (!parent) |
| 738 | parent = mDoc.first_node("install"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 739 | |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 740 | set_scale_values(1, 1); // Reset any previous scaling values |
| 741 | |
Ethan Yonker | 8e5692f | 2016-01-21 11:21:06 -0600 | [diff] [blame] | 742 | if (baseLanguageFile) |
| 743 | LoadLanguage(baseLanguageFile, NULL); |
| 744 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 745 | // Now, let's parse the XML |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 746 | child = parent->first_node("details"); |
| 747 | if (child) { |
Ethan Yonker | 1308d53 | 2016-01-14 22:21:49 -0600 | [diff] [blame] | 748 | int theme_ver = 0; |
| 749 | xml_node<>* themeversion = child->first_node("themeversion"); |
| 750 | if (themeversion && themeversion->value()) { |
| 751 | theme_ver = atoi(themeversion->value()); |
| 752 | } else { |
| 753 | LOGINFO("No themeversion in theme.\n"); |
| 754 | } |
| 755 | if (theme_ver != TW_THEME_VERSION) { |
| 756 | LOGINFO("theme version from xml: %i, expected %i\n", theme_ver, TW_THEME_VERSION); |
| 757 | if (package) { |
| 758 | gui_err("theme_ver_err=Custom theme version does not match TWRP version. Using stock theme."); |
| 759 | mDoc.clear(); |
Ethan Yonker | 8e5692f | 2016-01-21 11:21:06 -0600 | [diff] [blame] | 760 | return TW_THEME_VER_ERR; |
Ethan Yonker | 1308d53 | 2016-01-14 22:21:49 -0600 | [diff] [blame] | 761 | } else { |
| 762 | gui_print_color("warning", "Stock theme version does not match TWRP version.\n"); |
| 763 | } |
| 764 | } |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 765 | xml_node<>* resolution = child->first_node("resolution"); |
| 766 | if (resolution) { |
Ethan Yonker | 1308d53 | 2016-01-14 22:21:49 -0600 | [diff] [blame] | 767 | LOGINFO("Checking resolution...\n"); |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 768 | xml_attribute<>* width_attr = resolution->first_attribute("width"); |
| 769 | xml_attribute<>* height_attr = resolution->first_attribute("height"); |
| 770 | xml_attribute<>* noscale_attr = resolution->first_attribute("noscaling"); |
| 771 | if (width_attr && height_attr && !noscale_attr) { |
| 772 | int width = atoi(width_attr->value()); |
| 773 | int height = atoi(height_attr->value()); |
| 774 | int offx = 0, offy = 0; |
| 775 | #ifdef TW_ROUND_SCREEN |
| 776 | xml_node<>* roundscreen = child->first_node("roundscreen"); |
| 777 | if (roundscreen) { |
| 778 | LOGINFO("TW_ROUND_SCREEN := true, using round screen XML settings.\n"); |
| 779 | xml_attribute<>* offx_attr = roundscreen->first_attribute("offset_x"); |
| 780 | xml_attribute<>* offy_attr = roundscreen->first_attribute("offset_y"); |
| 781 | if (offx_attr) { |
| 782 | offx = atoi(offx_attr->value()); |
| 783 | } |
| 784 | if (offy_attr) { |
| 785 | offy = atoi(offy_attr->value()); |
| 786 | } |
| 787 | } |
| 788 | #endif |
| 789 | if (width != 0 && height != 0) { |
| 790 | float scale_w = ((float)gr_fb_width() - ((float)offx * 2.0)) / (float)width; |
| 791 | float scale_h = ((float)gr_fb_height() - ((float)offy * 2.0)) / (float)height; |
| 792 | #ifdef TW_ROUND_SCREEN |
| 793 | float scale_off_w = (float)gr_fb_width() / (float)width; |
| 794 | float scale_off_h = (float)gr_fb_height() / (float)height; |
| 795 | tw_x_offset = offx * scale_off_w; |
| 796 | tw_y_offset = offy * scale_off_h; |
| 797 | #endif |
| 798 | if (scale_w != 1 || scale_h != 1) { |
| 799 | LOGINFO("Scaling theme width %fx and height %fx, offsets x: %i y: %i\n", scale_w, scale_h, tw_x_offset, tw_y_offset); |
| 800 | set_scale_values(scale_w, scale_h); |
| 801 | } |
| 802 | } |
| 803 | } else { |
| 804 | LOGINFO("XML does not contain width and height, no scaling will be applied\n"); |
| 805 | } |
| 806 | } else { |
| 807 | LOGINFO("XML contains no resolution tag, no scaling will be applied.\n"); |
| 808 | } |
| 809 | } else { |
| 810 | LOGINFO("XML contains no details tag, no scaling will be applied.\n"); |
| 811 | } |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 812 | |
| 813 | if (languageFile) |
| 814 | LoadLanguage(languageFile, package); |
| 815 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 816 | LOGINFO("Loading resources...\n"); |
| 817 | child = parent->first_node("resources"); |
| 818 | if (child) |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 819 | mResources->LoadResources(child, package, "theme"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 820 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 821 | LOGINFO("Loading variables...\n"); |
| 822 | child = parent->first_node("variables"); |
| 823 | if (child) |
| 824 | LoadVariables(child); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 825 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 826 | LOGINFO("Loading mouse cursor...\n"); |
| 827 | child = parent->first_node("mousecursor"); |
| 828 | if(child) |
| 829 | PageManager::LoadCursorData(child); |
| 830 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 831 | LOGINFO("Loading pages...\n"); |
| 832 | // This may be NULL if no templates are present |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 833 | xmltemplate = parent->first_node("templates"); |
| 834 | if (xmltemplate) |
| 835 | templates.push_back(xmltemplate); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 836 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 837 | // Load styles if present |
| 838 | xmlstyle = parent->first_node("styles"); |
| 839 | if (xmlstyle) |
| 840 | styles.push_back(xmlstyle); |
| 841 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 842 | child = parent->first_node("pages"); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 843 | if (child) { |
| 844 | if (LoadPages(child)) { |
| 845 | LOGERR("PageSet::Load returning -1\n"); |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 846 | mDoc.clear(); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 847 | return -1; |
| 848 | } |
| 849 | } |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 850 | |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 851 | int ret = CheckInclude(package, &mDoc); |
| 852 | mDoc.clear(); |
| 853 | templates.clear(); |
| 854 | return ret; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 855 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 856 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 857 | int PageSet::CheckInclude(ZipArchive* package, xml_document<> *parentDoc) |
| 858 | { |
| 859 | xml_node<>* par; |
| 860 | xml_node<>* par2; |
| 861 | xml_node<>* chld; |
| 862 | xml_node<>* parent; |
| 863 | xml_node<>* child; |
| 864 | xml_node<>* xmltemplate; |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 865 | xml_node<>* xmlstyle; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 866 | long len; |
| 867 | char* xmlFile = NULL; |
| 868 | string filename; |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 869 | xml_document<> *doc = NULL; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 870 | |
| 871 | par = parentDoc->first_node("recovery"); |
| 872 | if (!par) { |
| 873 | par = parentDoc->first_node("install"); |
| 874 | } |
| 875 | if (!par) { |
| 876 | return 0; |
| 877 | } |
| 878 | |
| 879 | par2 = par->first_node("include"); |
| 880 | if (!par2) |
| 881 | return 0; |
| 882 | chld = par2->first_node("xmlfile"); |
| 883 | while (chld != NULL) { |
| 884 | xml_attribute<>* attr = chld->first_attribute("name"); |
| 885 | if (!attr) |
| 886 | break; |
| 887 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 888 | if (!package) { |
| 889 | // We can try to load the XML directly... |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 890 | filename = TWRES; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 891 | filename += attr->value(); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 892 | } else { |
| 893 | filename += attr->value(); |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 894 | } |
| 895 | xmlFile = PageManager::LoadFileToBuffer(filename, package); |
| 896 | if (xmlFile == NULL) { |
| 897 | LOGERR("PageSet::CheckInclude unable to load '%s'\n", filename.c_str()); |
| 898 | return -1; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 899 | } |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 900 | |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 901 | doc = new xml_document<>(); |
| 902 | doc->parse<0>(xmlFile); |
| 903 | |
| 904 | parent = doc->first_node("recovery"); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 905 | if (!parent) |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 906 | parent = doc->first_node("install"); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 907 | |
| 908 | // Now, let's parse the XML |
| 909 | LOGINFO("Loading included resources...\n"); |
| 910 | child = parent->first_node("resources"); |
| 911 | if (child) |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 912 | mResources->LoadResources(child, package, "theme"); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 913 | |
| 914 | LOGINFO("Loading included variables...\n"); |
| 915 | child = parent->first_node("variables"); |
| 916 | if (child) |
| 917 | LoadVariables(child); |
| 918 | |
| 919 | LOGINFO("Loading mouse cursor...\n"); |
| 920 | child = parent->first_node("mousecursor"); |
| 921 | if(child) |
| 922 | PageManager::LoadCursorData(child); |
| 923 | |
| 924 | LOGINFO("Loading included pages...\n"); |
| 925 | // This may be NULL if no templates are present |
| 926 | xmltemplate = parent->first_node("templates"); |
| 927 | if (xmltemplate) |
| 928 | templates.push_back(xmltemplate); |
| 929 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 930 | // Load styles if present |
| 931 | xmlstyle = parent->first_node("styles"); |
| 932 | if (xmlstyle) |
| 933 | styles.push_back(xmlstyle); |
| 934 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 935 | child = parent->first_node("pages"); |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 936 | if (child && LoadPages(child)) |
| 937 | { |
| 938 | templates.pop_back(); |
| 939 | doc->clear(); |
| 940 | delete doc; |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 941 | free(xmlFile); |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 942 | return -1; |
| 943 | } |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 944 | |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 945 | if (CheckInclude(package, doc)) { |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 946 | doc->clear(); |
| 947 | delete doc; |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 948 | free(xmlFile); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 949 | return -1; |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 950 | } |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 951 | doc->clear(); |
| 952 | delete doc; |
| 953 | free(xmlFile); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 954 | |
| 955 | chld = chld->next_sibling("xmlfile"); |
| 956 | } |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 957 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 958 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | int PageSet::SetPage(std::string page) |
| 962 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 963 | Page* tmp = FindPage(page); |
| 964 | if (tmp) |
| 965 | { |
| 966 | if (mCurrentPage) mCurrentPage->SetPageFocus(0); |
| 967 | mCurrentPage = tmp; |
| 968 | mCurrentPage->SetPageFocus(1); |
| 969 | mCurrentPage->NotifyVarChange("", ""); |
| 970 | return 0; |
| 971 | } |
| 972 | else |
| 973 | { |
| 974 | LOGERR("Unable to locate page (%s)\n", page.c_str()); |
| 975 | } |
| 976 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | int PageSet::SetOverlay(Page* page) |
| 980 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 981 | if (page) { |
| 982 | if (mOverlays.size() >= 10) { |
| 983 | LOGERR("Too many overlays requested, max is 10.\n"); |
| 984 | return -1; |
| 985 | } |
Matt Mower | d411f8d | 2015-04-09 16:04:12 -0500 | [diff] [blame] | 986 | |
| 987 | std::vector<Page*>::iterator iter; |
| 988 | for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) { |
| 989 | if ((*iter)->GetName() == page->GetName()) { |
| 990 | mOverlays.erase(iter); |
| 991 | // SetOverlay() is (and should stay) the only function which |
| 992 | // adds to mOverlays. Then, each page can appear at most once. |
| 993 | break; |
| 994 | } |
| 995 | } |
| 996 | |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 997 | page->SetPageFocus(1); |
| 998 | page->NotifyVarChange("", ""); |
| 999 | |
| 1000 | if (!mOverlays.empty()) |
| 1001 | mOverlays.back()->SetPageFocus(0); |
| 1002 | |
| 1003 | mOverlays.push_back(page); |
| 1004 | } else { |
| 1005 | if (!mOverlays.empty()) { |
| 1006 | mOverlays.back()->SetPageFocus(0); |
| 1007 | mOverlays.pop_back(); |
| 1008 | if (!mOverlays.empty()) |
| 1009 | mOverlays.back()->SetPageFocus(1); |
| 1010 | else if (mCurrentPage) |
| 1011 | mCurrentPage->SetPageFocus(1); // Just in case somehow the regular page lost focus, we'll set it again |
| 1012 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1013 | } |
| 1014 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1015 | } |
| 1016 | |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 1017 | const ResourceManager* PageSet::GetResources() |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1018 | { |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 1019 | return mResources; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | Page* PageSet::FindPage(std::string name) |
| 1023 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1024 | std::vector<Page*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1025 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1026 | for (iter = mPages.begin(); iter != mPages.end(); iter++) |
| 1027 | { |
| 1028 | if (name == (*iter)->GetName()) |
| 1029 | return (*iter); |
| 1030 | } |
| 1031 | return NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | int PageSet::LoadVariables(xml_node<>* vars) |
| 1035 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1036 | xml_node<>* child; |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 1037 | xml_attribute<> *name, *value, *persist; |
| 1038 | int p; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1039 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1040 | child = vars->first_node("variable"); |
| 1041 | while (child) |
| 1042 | { |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 1043 | name = child->first_attribute("name"); |
| 1044 | value = child->first_attribute("value"); |
| 1045 | persist = child->first_attribute("persist"); |
| 1046 | if(name && value) |
| 1047 | { |
Ethan Yonker | 751a85e | 2014-12-12 16:59:10 -0600 | [diff] [blame] | 1048 | if (strcmp(name->value(), "tw_x_offset") == 0) { |
| 1049 | tw_x_offset = atoi(value->value()); |
| 1050 | child = child->next_sibling("variable"); |
| 1051 | continue; |
| 1052 | } |
| 1053 | if (strcmp(name->value(), "tw_y_offset") == 0) { |
| 1054 | tw_y_offset = atoi(value->value()); |
| 1055 | child = child->next_sibling("variable"); |
| 1056 | continue; |
| 1057 | } |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 1058 | p = persist ? atoi(persist->value()) : 0; |
Ethan Yonker | 96acb3d | 2014-08-05 09:20:30 -0500 | [diff] [blame] | 1059 | string temp = value->value(); |
| 1060 | string valstr = gui_parse_text(temp); |
| 1061 | |
| 1062 | if (valstr.find("+") != string::npos) { |
| 1063 | string val1str = valstr; |
| 1064 | val1str = val1str.substr(0, val1str.find('+')); |
| 1065 | string val2str = valstr; |
| 1066 | val2str = val2str.substr(val2str.find('+') + 1, string::npos); |
| 1067 | int val1 = atoi(val1str.c_str()); |
| 1068 | int val2 = atoi(val2str.c_str()); |
| 1069 | int val = val1 + val2; |
| 1070 | |
| 1071 | DataManager::SetValue(name->value(), val, p); |
| 1072 | } else if (valstr.find("-") != string::npos) { |
| 1073 | string val1str = valstr; |
| 1074 | val1str = val1str.substr(0, val1str.find('-')); |
| 1075 | string val2str = valstr; |
| 1076 | val2str = val2str.substr(val2str.find('-') + 1, string::npos); |
| 1077 | int val1 = atoi(val1str.c_str()); |
| 1078 | int val2 = atoi(val2str.c_str()); |
| 1079 | int val = val1 - val2; |
| 1080 | |
| 1081 | DataManager::SetValue(name->value(), val, p); |
| 1082 | } else { |
| 1083 | DataManager::SetValue(name->value(), valstr, p); |
| 1084 | } |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 1085 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1086 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1087 | child = child->next_sibling("variable"); |
| 1088 | } |
| 1089 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1090 | } |
| 1091 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 1092 | int PageSet::LoadPages(xml_node<>* pages) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1093 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1094 | xml_node<>* child; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1095 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1096 | if (!pages) |
| 1097 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1098 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1099 | child = pages->first_node("page"); |
| 1100 | while (child != NULL) |
| 1101 | { |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 1102 | Page* page = new Page(child, &templates); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1103 | if (page->GetName().empty()) |
| 1104 | { |
| 1105 | LOGERR("Unable to process load page\n"); |
| 1106 | delete page; |
| 1107 | } |
| 1108 | else |
| 1109 | { |
| 1110 | mPages.push_back(page); |
| 1111 | } |
| 1112 | child = child->next_sibling("page"); |
| 1113 | } |
| 1114 | if (mPages.size() > 0) |
| 1115 | return 0; |
| 1116 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | int PageSet::IsCurrentPage(Page* page) |
| 1120 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1121 | return ((mCurrentPage && mCurrentPage == page) ? 1 : 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1122 | } |
| 1123 | |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 1124 | std::string PageSet::GetCurrentPage() const |
| 1125 | { |
| 1126 | return mCurrentPage ? mCurrentPage->GetName() : ""; |
| 1127 | } |
| 1128 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1129 | int PageSet::Render(void) |
| 1130 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1131 | int ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1132 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1133 | ret = (mCurrentPage ? mCurrentPage->Render() : -1); |
| 1134 | if (ret < 0) |
| 1135 | return ret; |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1136 | |
| 1137 | std::vector<Page*>::iterator iter; |
| 1138 | |
| 1139 | for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) { |
| 1140 | ret = ((*iter) ? (*iter)->Render() : -1); |
| 1141 | if (ret < 0) |
| 1142 | return ret; |
| 1143 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1144 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | int PageSet::Update(void) |
| 1148 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1149 | int ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1150 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1151 | ret = (mCurrentPage ? mCurrentPage->Update() : -1); |
| 1152 | if (ret < 0 || ret > 1) |
| 1153 | return ret; |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1154 | |
| 1155 | std::vector<Page*>::iterator iter; |
| 1156 | |
| 1157 | for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) { |
| 1158 | ret = ((*iter) ? (*iter)->Update() : -1); |
| 1159 | if (ret < 0) |
| 1160 | return ret; |
| 1161 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1162 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | int PageSet::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 1166 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1167 | if (!mOverlays.empty()) |
| 1168 | return mOverlays.back()->NotifyTouch(state, x, y); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1169 | |
| 1170 | return (mCurrentPage ? mCurrentPage->NotifyTouch(state, x, y) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1171 | } |
| 1172 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1173 | int PageSet::NotifyKey(int key, bool down) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1174 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1175 | if (!mOverlays.empty()) |
| 1176 | return mOverlays.back()->NotifyKey(key, down); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1177 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1178 | return (mCurrentPage ? mCurrentPage->NotifyKey(key, down) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1179 | } |
| 1180 | |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 1181 | int PageSet::NotifyCharInput(int ch) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1182 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1183 | if (!mOverlays.empty()) |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 1184 | return mOverlays.back()->NotifyCharInput(ch); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1185 | |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 1186 | return (mCurrentPage ? mCurrentPage->NotifyCharInput(ch) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | int PageSet::SetKeyBoardFocus(int inFocus) |
| 1190 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1191 | if (!mOverlays.empty()) |
| 1192 | return mOverlays.back()->SetKeyBoardFocus(inFocus); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1193 | |
| 1194 | return (mCurrentPage ? mCurrentPage->SetKeyBoardFocus(inFocus) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | int PageSet::NotifyVarChange(std::string varName, std::string value) |
| 1198 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1199 | std::vector<Page*>::iterator iter; |
| 1200 | |
| 1201 | for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) |
| 1202 | (*iter)->NotifyVarChange(varName, value); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1203 | |
| 1204 | return (mCurrentPage ? mCurrentPage->NotifyVarChange(varName, value) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1205 | } |
| 1206 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1207 | void PageSet::AddStringResource(std::string resource_source, std::string resource_name, std::string value) |
| 1208 | { |
| 1209 | mResources->AddStringResource(resource_source, resource_name, value); |
| 1210 | } |
| 1211 | |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1212 | char* PageManager::LoadFileToBuffer(std::string filename, ZipArchive* package) { |
| 1213 | size_t len; |
| 1214 | char* buffer = NULL; |
| 1215 | |
| 1216 | if (!package) { |
| 1217 | // We can try to load the XML directly... |
| 1218 | LOGINFO("PageManager::LoadFileToBuffer loading filename: '%s' directly\n", filename.c_str()); |
| 1219 | struct stat st; |
| 1220 | if(stat(filename.c_str(),&st) != 0) { |
| 1221 | // This isn't always an error, sometimes we request files that don't exist. |
| 1222 | return NULL; |
| 1223 | } |
| 1224 | |
| 1225 | len = (size_t)st.st_size; |
| 1226 | |
| 1227 | buffer = (char*) malloc(len + 1); |
| 1228 | if (!buffer) { |
| 1229 | LOGERR("PageManager::LoadFileToBuffer failed to malloc\n"); |
| 1230 | return NULL; |
| 1231 | } |
| 1232 | |
| 1233 | int fd = open(filename.c_str(), O_RDONLY); |
| 1234 | if (fd == -1) { |
| 1235 | LOGERR("PageManager::LoadFileToBuffer failed to open '%s' - (%s)\n", filename.c_str(), strerror(errno)); |
| 1236 | free(buffer); |
| 1237 | return NULL; |
| 1238 | } |
| 1239 | |
| 1240 | if (read(fd, buffer, len) < 0) { |
| 1241 | LOGERR("PageManager::LoadFileToBuffer failed to read '%s' - (%s)\n", filename.c_str(), strerror(errno)); |
| 1242 | free(buffer); |
| 1243 | close(fd); |
| 1244 | return NULL; |
| 1245 | } |
| 1246 | close(fd); |
| 1247 | } else { |
| 1248 | LOGINFO("PageManager::LoadFileToBuffer loading filename: '%s' from zip\n", filename.c_str()); |
| 1249 | const ZipEntry* zipentry = mzFindZipEntry(package, filename.c_str()); |
| 1250 | if (zipentry == NULL) { |
| 1251 | LOGERR("Unable to locate '%s' in zip file\n", filename.c_str()); |
| 1252 | return NULL; |
| 1253 | } |
| 1254 | |
| 1255 | // Allocate the buffer for the file |
| 1256 | len = mzGetZipEntryUncompLen(zipentry); |
| 1257 | buffer = (char*) malloc(len + 1); |
| 1258 | if (!buffer) |
| 1259 | return NULL; |
| 1260 | |
| 1261 | if (!mzExtractZipEntryToBuffer(package, zipentry, (unsigned char*) buffer)) { |
| 1262 | LOGERR("Unable to extract '%s'\n", filename.c_str()); |
| 1263 | free(buffer); |
| 1264 | return NULL; |
| 1265 | } |
| 1266 | } |
| 1267 | // NULL-terminate the string |
| 1268 | buffer[len] = 0x00; |
| 1269 | return buffer; |
| 1270 | } |
| 1271 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1272 | void PageManager::LoadLanguageListDir(string dir) { |
| 1273 | if (!TWFunc::Path_Exists(dir)) { |
| 1274 | LOGERR("LoadLanguageListDir '%s' path not found\n", dir.c_str()); |
| 1275 | return; |
| 1276 | } |
| 1277 | |
| 1278 | DIR *d = opendir(dir.c_str()); |
| 1279 | struct dirent *p; |
| 1280 | |
| 1281 | if (d == NULL) { |
| 1282 | LOGERR("LoadLanguageListDir error opening dir: '%s', %s\n", dir.c_str(), strerror(errno)); |
| 1283 | return; |
| 1284 | } |
| 1285 | |
| 1286 | while ((p = readdir(d))) { |
| 1287 | if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, "..") || strlen(p->d_name) < 5) |
| 1288 | continue; |
| 1289 | |
| 1290 | string file = p->d_name; |
| 1291 | if (file.substr(strlen(p->d_name) - 4) != ".xml") |
| 1292 | continue; |
| 1293 | string path = dir + p->d_name; |
| 1294 | string file_no_extn = file.substr(0, strlen(p->d_name) - 4); |
| 1295 | struct language_struct language_entry; |
| 1296 | language_entry.filename = file_no_extn; |
| 1297 | char* xmlFile = PageManager::LoadFileToBuffer(dir + p->d_name, NULL); |
| 1298 | if (xmlFile == NULL) { |
| 1299 | LOGERR("LoadLanguageListDir unable to load '%s'\n", language_entry.filename.c_str()); |
| 1300 | continue; |
| 1301 | } |
| 1302 | xml_document<> *doc = new xml_document<>(); |
| 1303 | doc->parse<0>(xmlFile); |
| 1304 | |
| 1305 | xml_node<>* parent = doc->first_node("language"); |
| 1306 | if (!parent) { |
| 1307 | LOGERR("Invalid language XML file '%s'\n", language_entry.filename.c_str()); |
| 1308 | } else { |
| 1309 | xml_node<>* child = parent->first_node("display"); |
| 1310 | if (child) { |
| 1311 | language_entry.displayvalue = child->value(); |
| 1312 | } else { |
| 1313 | LOGERR("No display value for '%s'\n", language_entry.filename.c_str()); |
| 1314 | language_entry.displayvalue = language_entry.filename; |
| 1315 | } |
| 1316 | Language_List.push_back(language_entry); |
| 1317 | } |
| 1318 | doc->clear(); |
| 1319 | delete doc; |
| 1320 | free(xmlFile); |
| 1321 | } |
| 1322 | closedir(d); |
| 1323 | } |
| 1324 | |
| 1325 | void PageManager::LoadLanguageList(ZipArchive* package) { |
| 1326 | Language_List.clear(); |
| 1327 | if (TWFunc::Path_Exists(TWRES "customlanguages")) |
| 1328 | TWFunc::removeDir(TWRES "customlanguages", true); |
| 1329 | if (package) { |
| 1330 | TWFunc::Recursive_Mkdir(TWRES "customlanguages"); |
| 1331 | struct utimbuf timestamp = { 1217592000, 1217592000 }; // 8/1/2008 default |
| 1332 | mzExtractRecursive(package, "languages", TWRES "customlanguages/", ×tamp, NULL, NULL, NULL); |
| 1333 | LoadLanguageListDir(TWRES "customlanguages/"); |
| 1334 | } else { |
| 1335 | LoadLanguageListDir(TWRES "languages/"); |
| 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | void PageManager::LoadLanguage(string filename) { |
| 1340 | string actual_filename; |
| 1341 | if (TWFunc::Path_Exists(TWRES "customlanguages/" + filename + ".xml")) |
| 1342 | actual_filename = TWRES "customlanguages/" + filename + ".xml"; |
| 1343 | else |
| 1344 | actual_filename = TWRES "languages/" + filename + ".xml"; |
| 1345 | char* xmlFile = PageManager::LoadFileToBuffer(actual_filename, NULL); |
| 1346 | if (xmlFile == NULL) |
| 1347 | LOGERR("Unable to load '%s'\n", actual_filename.c_str()); |
| 1348 | else { |
| 1349 | mCurrentSet->LoadLanguage(xmlFile, NULL); |
| 1350 | free(xmlFile); |
| 1351 | } |
| 1352 | PartitionManager.Translate_Partition_Display_Names(); |
| 1353 | } |
| 1354 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1355 | int PageManager::LoadPackage(std::string name, std::string package, std::string startpage) |
| 1356 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1357 | int fd; |
| 1358 | ZipArchive zip, *pZip = NULL; |
| 1359 | long len; |
| 1360 | char* xmlFile = NULL; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1361 | char* languageFile = NULL; |
Ethan Yonker | 8e5692f | 2016-01-21 11:21:06 -0600 | [diff] [blame] | 1362 | char* baseLanguageFile = NULL; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1363 | PageSet* pageSet = NULL; |
| 1364 | int ret; |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1365 | MemMapping map; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1366 | |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 1367 | mReloadTheme = false; |
| 1368 | mStartPage = startpage; |
| 1369 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1370 | // Open the XML file |
| 1371 | LOGINFO("Loading package: %s (%s)\n", name.c_str(), package.c_str()); |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1372 | if (package.size() > 4 && package.substr(package.size() - 4) != ".zip") |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1373 | { |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1374 | LOGINFO("Load XML directly\n"); |
Ethan Yonker | 751a85e | 2014-12-12 16:59:10 -0600 | [diff] [blame] | 1375 | tw_x_offset = TW_X_OFFSET; |
| 1376 | tw_y_offset = TW_Y_OFFSET; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1377 | LoadLanguageList(NULL); |
| 1378 | languageFile = LoadFileToBuffer(TWRES "languages/en.xml", NULL); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1379 | } |
| 1380 | else |
| 1381 | { |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1382 | LOGINFO("Loading zip theme\n"); |
Ethan Yonker | 751a85e | 2014-12-12 16:59:10 -0600 | [diff] [blame] | 1383 | tw_x_offset = 0; |
| 1384 | tw_y_offset = 0; |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1385 | if (!TWFunc::Path_Exists(package)) |
| 1386 | return -1; |
| 1387 | if (sysMapFile(package.c_str(), &map) != 0) { |
| 1388 | LOGERR("Failed to map '%s'\n", package.c_str()); |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1389 | goto error; |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1390 | } |
| 1391 | if (mzOpenZipArchive(map.addr, map.length, &zip)) { |
| 1392 | LOGERR("Unable to open zip archive '%s'\n", package.c_str()); |
| 1393 | sysReleaseMap(&map); |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1394 | goto error; |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1395 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1396 | pZip = &zip; |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1397 | package = "ui.xml"; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1398 | LoadLanguageList(pZip); |
| 1399 | languageFile = LoadFileToBuffer("languages/en.xml", pZip); |
Ethan Yonker | 8e5692f | 2016-01-21 11:21:06 -0600 | [diff] [blame] | 1400 | baseLanguageFile = LoadFileToBuffer(TWRES "languages/en.xml", NULL); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1401 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1402 | |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1403 | xmlFile = LoadFileToBuffer(package, pZip); |
| 1404 | if (xmlFile == NULL) { |
| 1405 | goto error; |
| 1406 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1407 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1408 | // Before loading, mCurrentSet must be the loading package so we can find resources |
| 1409 | pageSet = mCurrentSet; |
| 1410 | mCurrentSet = new PageSet(xmlFile); |
Ethan Yonker | 8e5692f | 2016-01-21 11:21:06 -0600 | [diff] [blame] | 1411 | ret = mCurrentSet->Load(pZip, xmlFile, languageFile, baseLanguageFile); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1412 | if (languageFile) { |
| 1413 | free(languageFile); |
| 1414 | languageFile = NULL; |
| 1415 | } |
Ethan Yonker | 8e5692f | 2016-01-21 11:21:06 -0600 | [diff] [blame] | 1416 | if (ret == 0) { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1417 | mCurrentSet->SetPage(startpage); |
| 1418 | mPageSets.insert(std::pair<std::string, PageSet*>(name, mCurrentSet)); |
Ethan Yonker | 8e5692f | 2016-01-21 11:21:06 -0600 | [diff] [blame] | 1419 | } else { |
| 1420 | if (ret != TW_THEME_VER_ERR) |
| 1421 | LOGERR("Package %s failed to load.\n", name.c_str()); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1422 | } |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 1423 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1424 | // The first successful package we loaded is the base |
| 1425 | if (mBaseSet == NULL) |
| 1426 | mBaseSet = mCurrentSet; |
| 1427 | |
| 1428 | mCurrentSet = pageSet; |
| 1429 | |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1430 | if (pZip) { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1431 | mzCloseZipArchive(pZip); |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1432 | sysReleaseMap(&map); |
| 1433 | } |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1434 | free(xmlFile); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1435 | if (languageFile) |
| 1436 | free(languageFile); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1437 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1438 | |
| 1439 | error: |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1440 | // Sometimes we get here without a real error |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1441 | if (pZip) { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1442 | mzCloseZipArchive(pZip); |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1443 | sysReleaseMap(&map); |
| 1444 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1445 | if (xmlFile) |
| 1446 | free(xmlFile); |
| 1447 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | PageSet* PageManager::FindPackage(std::string name) |
| 1451 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1452 | std::map<std::string, PageSet*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1453 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1454 | iter = mPageSets.find(name); |
| 1455 | if (iter != mPageSets.end()) |
| 1456 | return (*iter).second; |
| 1457 | |
| 1458 | LOGERR("Unable to locate package %s\n", name.c_str()); |
| 1459 | return NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | PageSet* PageManager::SelectPackage(std::string name) |
| 1463 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1464 | LOGINFO("Switching packages (%s)\n", name.c_str()); |
| 1465 | PageSet* tmp; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1466 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1467 | tmp = FindPackage(name); |
| 1468 | if (tmp) |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 1469 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1470 | mCurrentSet = tmp; |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 1471 | mCurrentSet->NotifyVarChange("", ""); |
| 1472 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1473 | else |
| 1474 | LOGERR("Unable to find package.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1475 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1476 | return mCurrentSet; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | int PageManager::ReloadPackage(std::string name, std::string package) |
| 1480 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1481 | std::map<std::string, PageSet*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1482 | |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 1483 | mReloadTheme = false; |
| 1484 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1485 | iter = mPageSets.find(name); |
| 1486 | if (iter == mPageSets.end()) |
| 1487 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1488 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1489 | if(mMouseCursor) |
| 1490 | mMouseCursor->ResetData(gr_fb_width(), gr_fb_height()); |
| 1491 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1492 | PageSet* set = (*iter).second; |
| 1493 | mPageSets.erase(iter); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1494 | |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 1495 | if (LoadPackage(name, package, mStartPage) != 0) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1496 | { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1497 | LOGINFO("Failed to load package '%s'.\n", package.c_str()); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1498 | mPageSets.insert(std::pair<std::string, PageSet*>(name, set)); |
| 1499 | return -1; |
| 1500 | } |
| 1501 | if (mCurrentSet == set) |
| 1502 | SelectPackage(name); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 1503 | if (mBaseSet == set) |
| 1504 | mBaseSet = mCurrentSet; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1505 | delete set; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1506 | GUIConsole::Translate_Now(); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1507 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | void PageManager::ReleasePackage(std::string name) |
| 1511 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1512 | std::map<std::string, PageSet*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1513 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1514 | iter = mPageSets.find(name); |
| 1515 | if (iter == mPageSets.end()) |
| 1516 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1517 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1518 | PageSet* set = (*iter).second; |
| 1519 | mPageSets.erase(iter); |
| 1520 | delete set; |
| 1521 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1522 | } |
| 1523 | |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 1524 | int PageManager::RunReload() { |
| 1525 | int ret_val = 0; |
| 1526 | std::string theme_path; |
| 1527 | |
| 1528 | if (!mReloadTheme) |
| 1529 | return 0; |
| 1530 | |
| 1531 | mReloadTheme = false; |
| 1532 | theme_path = DataManager::GetSettingsStoragePath(); |
| 1533 | if (PartitionManager.Mount_By_Path(theme_path.c_str(), 1) < 0) { |
| 1534 | LOGERR("Unable to mount %s during gui_reload_theme function.\n", theme_path.c_str()); |
| 1535 | ret_val = 1; |
| 1536 | } |
| 1537 | |
| 1538 | theme_path += "/TWRP/theme/ui.zip"; |
| 1539 | if (ret_val != 0 || ReloadPackage("TWRP", theme_path) != 0) |
| 1540 | { |
| 1541 | // Loading the custom theme failed - try loading the stock theme |
| 1542 | LOGINFO("Attempting to reload stock theme...\n"); |
| 1543 | if (ReloadPackage("TWRP", TWRES "ui.xml")) |
| 1544 | { |
| 1545 | LOGERR("Failed to load base packages.\n"); |
| 1546 | ret_val = 1; |
| 1547 | } |
| 1548 | } |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1549 | if (ret_val == 0) { |
| 1550 | if (DataManager::GetStrValue("tw_language") != "en.xml") { |
| 1551 | LOGINFO("Loading language '%s'\n", DataManager::GetStrValue("tw_language").c_str()); |
| 1552 | LoadLanguage(DataManager::GetStrValue("tw_language")); |
| 1553 | } |
| 1554 | } |
| 1555 | |
| 1556 | // This makes the console re-translate |
| 1557 | last_message_count = 0; |
| 1558 | gConsole.clear(); |
| 1559 | gConsoleColor.clear(); |
| 1560 | |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 1561 | return ret_val; |
| 1562 | } |
| 1563 | |
| 1564 | void PageManager::RequestReload() { |
| 1565 | mReloadTheme = true; |
| 1566 | } |
| 1567 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1568 | int PageManager::ChangePage(std::string name) |
| 1569 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1570 | DataManager::SetValue("tw_operation_state", 0); |
| 1571 | int ret = (mCurrentSet ? mCurrentSet->SetPage(name) : -1); |
| 1572 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1573 | } |
| 1574 | |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 1575 | std::string PageManager::GetCurrentPage() |
| 1576 | { |
| 1577 | return mCurrentSet ? mCurrentSet->GetCurrentPage() : ""; |
| 1578 | } |
| 1579 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1580 | int PageManager::ChangeOverlay(std::string name) |
| 1581 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1582 | if (name.empty()) |
| 1583 | return mCurrentSet->SetOverlay(NULL); |
| 1584 | else |
| 1585 | { |
Ethan Yonker | 1308d53 | 2016-01-14 22:21:49 -0600 | [diff] [blame] | 1586 | Page* page = mCurrentSet ? mCurrentSet->FindPage(name) : NULL; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1587 | return mCurrentSet->SetOverlay(page); |
| 1588 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1589 | } |
| 1590 | |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 1591 | const ResourceManager* PageManager::GetResources() |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1592 | { |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 1593 | return (mCurrentSet ? mCurrentSet->GetResources() : NULL); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1594 | } |
| 1595 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1596 | int PageManager::IsCurrentPage(Page* page) |
| 1597 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1598 | return (mCurrentSet ? mCurrentSet->IsCurrentPage(page) : 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | int PageManager::Render(void) |
| 1602 | { |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 1603 | if(blankTimer.isScreenOff()) |
| 1604 | return 0; |
| 1605 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1606 | int res = (mCurrentSet ? mCurrentSet->Render() : -1); |
| 1607 | if(mMouseCursor) |
| 1608 | mMouseCursor->Render(); |
| 1609 | return res; |
| 1610 | } |
| 1611 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1612 | HardwareKeyboard *PageManager::GetHardwareKeyboard() |
| 1613 | { |
| 1614 | if(!mHardwareKeyboard) |
| 1615 | mHardwareKeyboard = new HardwareKeyboard(); |
| 1616 | return mHardwareKeyboard; |
| 1617 | } |
| 1618 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 1619 | xml_node<>* PageManager::FindStyle(std::string name) |
| 1620 | { |
| 1621 | for (std::vector<xml_node<>*>::iterator itr = mCurrentSet->styles.begin(); itr != mCurrentSet->styles.end(); itr++) { |
| 1622 | xml_node<>* node = (*itr)->first_node("style"); |
| 1623 | |
| 1624 | while (node) { |
| 1625 | if (!node->first_attribute("name")) |
| 1626 | continue; |
| 1627 | |
| 1628 | if (name == node->first_attribute("name")->value()) |
| 1629 | return node; |
| 1630 | node = node->next_sibling("style"); |
| 1631 | } |
| 1632 | } |
| 1633 | return NULL; |
| 1634 | } |
| 1635 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1636 | MouseCursor *PageManager::GetMouseCursor() |
| 1637 | { |
| 1638 | if(!mMouseCursor) |
| 1639 | mMouseCursor = new MouseCursor(gr_fb_width(), gr_fb_height()); |
| 1640 | return mMouseCursor; |
| 1641 | } |
| 1642 | |
| 1643 | void PageManager::LoadCursorData(xml_node<>* node) |
| 1644 | { |
| 1645 | if(!mMouseCursor) |
| 1646 | mMouseCursor = new MouseCursor(gr_fb_width(), gr_fb_height()); |
| 1647 | |
| 1648 | mMouseCursor->LoadData(node); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1649 | } |
| 1650 | |
| 1651 | int PageManager::Update(void) |
| 1652 | { |
that | fb759d4 | 2015-01-11 12:16:53 +0100 | [diff] [blame] | 1653 | if(blankTimer.isScreenOff()) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1654 | return 0; |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1655 | |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 1656 | if (RunReload()) |
| 1657 | return -2; |
| 1658 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1659 | int res = (mCurrentSet ? mCurrentSet->Update() : -1); |
| 1660 | |
| 1661 | if(mMouseCursor) |
| 1662 | { |
| 1663 | int c_res = mMouseCursor->Update(); |
| 1664 | if(c_res > res) |
| 1665 | res = c_res; |
| 1666 | } |
| 1667 | return res; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | int PageManager::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 1671 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1672 | return (mCurrentSet ? mCurrentSet->NotifyTouch(state, x, y) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1673 | } |
| 1674 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1675 | int PageManager::NotifyKey(int key, bool down) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1676 | { |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1677 | return (mCurrentSet ? mCurrentSet->NotifyKey(key, down) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1678 | } |
| 1679 | |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 1680 | int PageManager::NotifyCharInput(int ch) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1681 | { |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 1682 | return (mCurrentSet ? mCurrentSet->NotifyCharInput(ch) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1683 | } |
| 1684 | |
| 1685 | int PageManager::SetKeyBoardFocus(int inFocus) |
| 1686 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1687 | return (mCurrentSet ? mCurrentSet->SetKeyBoardFocus(inFocus) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1688 | } |
| 1689 | |
| 1690 | int PageManager::NotifyVarChange(std::string varName, std::string value) |
| 1691 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1692 | return (mCurrentSet ? mCurrentSet->NotifyVarChange(varName, value) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1693 | } |
| 1694 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1695 | void PageManager::AddStringResource(std::string resource_source, std::string resource_name, std::string value) |
| 1696 | { |
| 1697 | if (mCurrentSet) |
| 1698 | mCurrentSet->AddStringResource(resource_source, resource_name, value); |
| 1699 | } |
| 1700 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1701 | extern "C" void gui_notifyVarChange(const char *name, const char* value) |
| 1702 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1703 | if (!gGuiRunning) |
| 1704 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1705 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1706 | PageManager::NotifyVarChange(name, value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1707 | } |