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