Matt Mower | e04eee7 | 2016-12-31 00:38:57 -0600 | [diff] [blame^] | 1 | /* |
| 2 | Copyright 2017 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 | */ |
| 18 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 19 | // pages.hpp - Base classes for page manager of GUI |
| 20 | |
Dees_Troy | e4a8811 | 2012-12-18 21:29:33 +0000 | [diff] [blame] | 21 | #ifndef _PAGES_HEADER_HPP |
| 22 | #define _PAGES_HEADER_HPP |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 23 | |
Dees Troy | b7ae098 | 2013-09-10 20:47:35 +0000 | [diff] [blame] | 24 | #include "../minzip/Zip.h" |
that | fb759d4 | 2015-01-11 12:16:53 +0100 | [diff] [blame] | 25 | #include <vector> |
| 26 | #include <map> |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 27 | #include <string> |
that | fb759d4 | 2015-01-11 12:16:53 +0100 | [diff] [blame] | 28 | #include "rapidxml.hpp" |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 29 | #include "gui.hpp" |
that | fb759d4 | 2015-01-11 12:16:53 +0100 | [diff] [blame] | 30 | using namespace rapidxml; |
| 31 | |
| 32 | enum TOUCH_STATE { |
| 33 | TOUCH_START = 0, |
| 34 | TOUCH_DRAG = 1, |
| 35 | TOUCH_RELEASE = 2, |
| 36 | TOUCH_HOLD = 3, |
| 37 | TOUCH_REPEAT = 4 |
| 38 | }; |
Dees Troy | b7ae098 | 2013-09-10 20:47:35 +0000 | [diff] [blame] | 39 | |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 40 | struct COLOR { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 41 | unsigned char red; |
| 42 | unsigned char green; |
| 43 | unsigned char blue; |
| 44 | unsigned char alpha; |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 45 | COLOR() : red(0), green(0), blue(0), alpha(0) {} |
| 46 | COLOR(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255) |
| 47 | : red(r), green(g), blue(b), alpha(a) {} |
| 48 | }; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 49 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 50 | struct language_struct { |
| 51 | std::string filename; |
| 52 | std::string displayvalue; |
| 53 | }; |
| 54 | |
Xuefer | cac6ace | 2016-02-01 02:28:55 +0800 | [diff] [blame] | 55 | inline bool operator < (const language_struct& language1, const language_struct& language2) |
| 56 | { |
| 57 | return language1.displayvalue < language2.displayvalue; |
| 58 | } |
| 59 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 60 | extern std::vector<language_struct> Language_List; |
| 61 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 62 | // Utility Functions |
| 63 | int ConvertStrToColor(std::string str, COLOR* color); |
| 64 | int gui_forceRender(void); |
| 65 | int gui_changePage(std::string newPage); |
| 66 | int gui_changeOverlay(std::string newPage); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 67 | |
| 68 | class Resource; |
| 69 | class ResourceManager; |
| 70 | class RenderObject; |
| 71 | class ActionObject; |
| 72 | class InputObject; |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 73 | class MouseCursor; |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 74 | class GUIObject; |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 75 | class HardwareKeyboard; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 76 | |
| 77 | class Page |
| 78 | { |
| 79 | public: |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 80 | Page(xml_node<>* page, std::vector<xml_node<>*> *templates); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 81 | virtual ~Page(); |
| 82 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 83 | std::string GetName(void) { return mName; } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 84 | |
| 85 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 86 | virtual int Render(void); |
| 87 | virtual int Update(void); |
| 88 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 89 | virtual int NotifyKey(int key, bool down); |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 90 | virtual int NotifyCharInput(int ch); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 91 | virtual int SetKeyBoardFocus(int inFocus); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 92 | virtual int NotifyVarChange(std::string varName, std::string value); |
| 93 | virtual void SetPageFocus(int inFocus); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 94 | |
| 95 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 96 | std::string mName; |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 97 | std::vector<GUIObject*> mObjects; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 98 | std::vector<RenderObject*> mRenders; |
| 99 | std::vector<ActionObject*> mActions; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 100 | std::vector<InputObject*> mInputs; |
| 101 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 102 | ActionObject* mTouchStart; |
| 103 | COLOR mBackground; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 104 | |
| 105 | protected: |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 106 | bool ProcessNode(xml_node<>* page, std::vector<xml_node<>*> *templates, int depth); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 107 | }; |
| 108 | |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 109 | struct LoadingContext; |
| 110 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 111 | class PageSet |
| 112 | { |
| 113 | public: |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 114 | PageSet(); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 115 | virtual ~PageSet(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 116 | |
| 117 | public: |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 118 | int Load(LoadingContext& ctx, const std::string& filename); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 119 | int LoadLanguage(char* languageFile, ZipArchive* package); |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 120 | void MakeEmergencyConsoleIfNeeded(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 121 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 122 | Page* FindPage(std::string name); |
| 123 | int SetPage(std::string page); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 124 | int SetOverlay(Page* page); |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 125 | const ResourceManager* GetResources(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 126 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 127 | // Helper routine for identifing if we're the current page |
| 128 | int IsCurrentPage(Page* page); |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 129 | std::string GetCurrentPage() const; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 130 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 131 | // These are routing routines |
| 132 | int Render(void); |
| 133 | int Update(void); |
| 134 | int NotifyTouch(TOUCH_STATE state, int x, int y); |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 135 | int NotifyKey(int key, bool down); |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 136 | int NotifyCharInput(int ch); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 137 | int SetKeyBoardFocus(int inFocus); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 138 | int NotifyVarChange(std::string varName, std::string value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 139 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 140 | void AddStringResource(std::string resource_source, std::string resource_name, std::string value); |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 141 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 142 | protected: |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 143 | int LoadDetails(LoadingContext& ctx, xml_node<>* root); |
| 144 | int LoadPages(LoadingContext& ctx, xml_node<>* pages); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 145 | int LoadVariables(xml_node<>* vars); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 146 | |
| 147 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 148 | ResourceManager* mResources; |
| 149 | std::vector<Page*> mPages; |
| 150 | Page* mCurrentPage; |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 151 | std::vector<Page*> mOverlays; // Special case for popup dialogs and the lock screen |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | class PageManager |
| 155 | { |
| 156 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 157 | // Used by GUI |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 158 | static char* LoadFileToBuffer(std::string filename, ZipArchive* package); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 159 | static void LoadLanguageList(ZipArchive* package); |
| 160 | static void LoadLanguage(std::string filename); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 161 | static int LoadPackage(std::string name, std::string package, std::string startpage); |
| 162 | static PageSet* SelectPackage(std::string name); |
| 163 | static int ReloadPackage(std::string name, std::string package); |
| 164 | static void ReleasePackage(std::string name); |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 165 | static int RunReload(); |
| 166 | static void RequestReload(); |
Ethan Yonker | afde098 | 2016-01-23 08:55:35 -0600 | [diff] [blame] | 167 | static void SetStartPage(const std::string& page_name); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 168 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 169 | // Used for actions and pages |
| 170 | static int ChangePage(std::string name); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 171 | static int ChangeOverlay(std::string name); |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 172 | static const ResourceManager* GetResources(); |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 173 | static std::string GetCurrentPage(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 174 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 175 | // Helper to identify if a particular page is the active page |
| 176 | static int IsCurrentPage(Page* page); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 177 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 178 | // These are routing routines |
| 179 | static int Render(void); |
| 180 | static int Update(void); |
| 181 | static int NotifyTouch(TOUCH_STATE state, int x, int y); |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 182 | static int NotifyKey(int key, bool down); |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 183 | static int NotifyCharInput(int ch); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 184 | static int SetKeyBoardFocus(int inFocus); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 185 | static int NotifyVarChange(std::string varName, std::string value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 186 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 187 | static MouseCursor *GetMouseCursor(); |
| 188 | static void LoadCursorData(xml_node<>* node); |
| 189 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 190 | static HardwareKeyboard *GetHardwareKeyboard(); |
| 191 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 192 | static xml_node<>* FindStyle(std::string name); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 193 | static void AddStringResource(std::string resource_source, std::string resource_name, std::string value); |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 194 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 195 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 196 | static PageSet* FindPackage(std::string name); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 197 | static void LoadLanguageListDir(std::string dir); |
| 198 | static void Translate_Partition(const char* path, const char* resource_name, const char* default_value); |
| 199 | static void Translate_Partition(const char* path, const char* resource_name, const char* default_value, const char* storage_resource_name, const char* storage_default_value); |
| 200 | static void Translate_Partition_Display_Names(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 201 | |
| 202 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 203 | static std::map<std::string, PageSet*> mPageSets; |
| 204 | static PageSet* mCurrentSet; |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 205 | static MouseCursor *mMouseCursor; |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 206 | static HardwareKeyboard *mHardwareKeyboard; |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 207 | static bool mReloadTheme; |
| 208 | static std::string mStartPage; |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 209 | static LoadingContext* currentLoadingContext; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 210 | }; |
| 211 | |
Dees_Troy | e4a8811 | 2012-12-18 21:29:33 +0000 | [diff] [blame] | 212 | #endif // _PAGES_HEADER_HPP |