blob: 7688604dcad0d63b756ecde49dd45b30747ac368 [file] [log] [blame]
Matt Mowere04eee72016-12-31 00:38:57 -06001/*
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_Troy51a0e822012-09-05 15:24:24 -040019// pages.hpp - Base classes for page manager of GUI
20
Dees_Troye4a88112012-12-18 21:29:33 +000021#ifndef _PAGES_HEADER_HPP
22#define _PAGES_HEADER_HPP
Dees_Troy51a0e822012-09-05 15:24:24 -040023
thatfb759d42015-01-11 12:16:53 +010024#include <vector>
25#include <map>
Ethan Yonker74db1572015-10-28 12:44:49 -050026#include <string>
bigbiff673c7ae2020-12-02 19:44:56 -050027#include "ziparchive/zip_archive.h"
thatfb759d42015-01-11 12:16:53 +010028#include "rapidxml.hpp"
Ethan Yonker74db1572015-10-28 12:44:49 -050029#include "gui.hpp"
thatfb759d42015-01-11 12:16:53 +010030using namespace rapidxml;
31
32enum TOUCH_STATE {
33 TOUCH_START = 0,
34 TOUCH_DRAG = 1,
35 TOUCH_RELEASE = 2,
36 TOUCH_HOLD = 3,
37 TOUCH_REPEAT = 4
38};
Dees Troyb7ae0982013-09-10 20:47:35 +000039
thatf6ed8fc2015-02-14 20:23:16 +010040struct COLOR {
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020041 unsigned char red;
42 unsigned char green;
43 unsigned char blue;
44 unsigned char alpha;
thatf6ed8fc2015-02-14 20:23:16 +010045 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_Troy51a0e822012-09-05 15:24:24 -040049
Ethan Yonker74db1572015-10-28 12:44:49 -050050struct language_struct {
51 std::string filename;
52 std::string displayvalue;
53};
54
Xuefercac6ace2016-02-01 02:28:55 +080055inline bool operator < (const language_struct& language1, const language_struct& language2)
56{
57 return language1.displayvalue < language2.displayvalue;
58}
59
Ethan Yonker74db1572015-10-28 12:44:49 -050060extern std::vector<language_struct> Language_List;
61
Dees_Troy51a0e822012-09-05 15:24:24 -040062// Utility Functions
63int ConvertStrToColor(std::string str, COLOR* color);
64int gui_forceRender(void);
65int gui_changePage(std::string newPage);
66int gui_changeOverlay(std::string newPage);
Dees_Troy51a0e822012-09-05 15:24:24 -040067
68class Resource;
69class ResourceManager;
70class RenderObject;
71class ActionObject;
72class InputObject;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010073class MouseCursor;
Vojtech Bocekbfb63342014-02-08 00:32:31 +010074class GUIObject;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010075class HardwareKeyboard;
Dees_Troy51a0e822012-09-05 15:24:24 -040076
77class Page
78{
79public:
thatb63e2f92015-06-27 21:35:11 +020080 Page(xml_node<>* page, std::vector<xml_node<>*> *templates);
Vojtech Bocekbfb63342014-02-08 00:32:31 +010081 virtual ~Page();
82
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020083 std::string GetName(void) { return mName; }
Dees_Troy51a0e822012-09-05 15:24:24 -040084
85public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020086 virtual int Render(void);
87 virtual int Update(void);
88 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010089 virtual int NotifyKey(int key, bool down);
that8834a0f2016-01-05 23:29:30 +010090 virtual int NotifyCharInput(int ch);
Dees_Troy51a0e822012-09-05 15:24:24 -040091 virtual int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020092 virtual int NotifyVarChange(std::string varName, std::string value);
93 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -040094
95protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020096 std::string mName;
Vojtech Bocekbfb63342014-02-08 00:32:31 +010097 std::vector<GUIObject*> mObjects;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020098 std::vector<RenderObject*> mRenders;
99 std::vector<ActionObject*> mActions;
Dees_Troy51a0e822012-09-05 15:24:24 -0400100 std::vector<InputObject*> mInputs;
101
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200102 ActionObject* mTouchStart;
103 COLOR mBackground;
Dees_Troy51a0e822012-09-05 15:24:24 -0400104
105protected:
thatb63e2f92015-06-27 21:35:11 +0200106 bool ProcessNode(xml_node<>* page, std::vector<xml_node<>*> *templates, int depth);
Dees_Troy51a0e822012-09-05 15:24:24 -0400107};
108
that6a894592016-03-13 17:51:28 +0100109struct LoadingContext;
110
Dees_Troy51a0e822012-09-05 15:24:24 -0400111class PageSet
112{
113public:
that6a894592016-03-13 17:51:28 +0100114 PageSet();
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200115 virtual ~PageSet();
Dees_Troy51a0e822012-09-05 15:24:24 -0400116
117public:
that6a894592016-03-13 17:51:28 +0100118 int Load(LoadingContext& ctx, const std::string& filename);
bigbiff673c7ae2020-12-02 19:44:56 -0500119 int LoadLanguage(char* languageFile, ZipArchiveHandle package);
that6a894592016-03-13 17:51:28 +0100120 void MakeEmergencyConsoleIfNeeded();
Dees_Troy51a0e822012-09-05 15:24:24 -0400121
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200122 Page* FindPage(std::string name);
123 int SetPage(std::string page);
Dees_Troy51a0e822012-09-05 15:24:24 -0400124 int SetOverlay(Page* page);
that74ac6062015-03-04 22:39:34 +0100125 const ResourceManager* GetResources();
Dees_Troy51a0e822012-09-05 15:24:24 -0400126
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200127 // Helper routine for identifing if we're the current page
128 int IsCurrentPage(Page* page);
that10ae24f2015-12-26 20:53:51 +0100129 std::string GetCurrentPage() const;
Dees_Troy51a0e822012-09-05 15:24:24 -0400130
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200131 // These are routing routines
132 int Render(void);
133 int Update(void);
134 int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100135 int NotifyKey(int key, bool down);
that8834a0f2016-01-05 23:29:30 +0100136 int NotifyCharInput(int ch);
Dees_Troy51a0e822012-09-05 15:24:24 -0400137 int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200138 int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400139
Ethan Yonker74db1572015-10-28 12:44:49 -0500140 void AddStringResource(std::string resource_source, std::string resource_name, std::string value);
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600141
Dees_Troy51a0e822012-09-05 15:24:24 -0400142protected:
that6a894592016-03-13 17:51:28 +0100143 int LoadDetails(LoadingContext& ctx, xml_node<>* root);
144 int LoadPages(LoadingContext& ctx, xml_node<>* pages);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200145 int LoadVariables(xml_node<>* vars);
Dees_Troy51a0e822012-09-05 15:24:24 -0400146
147protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200148 ResourceManager* mResources;
149 std::vector<Page*> mPages;
150 Page* mCurrentPage;
Ethan Yonker1c273312015-03-16 12:18:56 -0500151 std::vector<Page*> mOverlays; // Special case for popup dialogs and the lock screen
Dees_Troy51a0e822012-09-05 15:24:24 -0400152};
153
154class PageManager
155{
156public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200157 // Used by GUI
bigbiff673c7ae2020-12-02 19:44:56 -0500158 static char* LoadFileToBuffer(std::string filename, ZipArchiveHandle package);
159 static void LoadLanguageList(ZipArchiveHandle package);
Ethan Yonker74db1572015-10-28 12:44:49 -0500160 static void LoadLanguage(std::string filename);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200161 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 Yonkere0f1f3b2015-10-27 09:49:01 -0500165 static int RunReload();
166 static void RequestReload();
Ethan Yonkerafde0982016-01-23 08:55:35 -0600167 static void SetStartPage(const std::string& page_name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400168
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200169 // Used for actions and pages
170 static int ChangePage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400171 static int ChangeOverlay(std::string name);
that74ac6062015-03-04 22:39:34 +0100172 static const ResourceManager* GetResources();
that10ae24f2015-12-26 20:53:51 +0100173 static std::string GetCurrentPage();
Dees_Troy51a0e822012-09-05 15:24:24 -0400174
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200175 // Helper to identify if a particular page is the active page
176 static int IsCurrentPage(Page* page);
Dees_Troy51a0e822012-09-05 15:24:24 -0400177
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200178 // 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 Bocek0b7fe502014-03-13 17:36:52 +0100182 static int NotifyKey(int key, bool down);
that8834a0f2016-01-05 23:29:30 +0100183 static int NotifyCharInput(int ch);
Dees_Troy51a0e822012-09-05 15:24:24 -0400184 static int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200185 static int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400186
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100187 static MouseCursor *GetMouseCursor();
188 static void LoadCursorData(xml_node<>* node);
189
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100190 static HardwareKeyboard *GetHardwareKeyboard();
191
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600192 static xml_node<>* FindStyle(std::string name);
Ethan Yonker74db1572015-10-28 12:44:49 -0500193 static void AddStringResource(std::string resource_source, std::string resource_name, std::string value);
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600194
Dees_Troy51a0e822012-09-05 15:24:24 -0400195protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200196 static PageSet* FindPackage(std::string name);
Ethan Yonker74db1572015-10-28 12:44:49 -0500197 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_Troy51a0e822012-09-05 15:24:24 -0400201
202protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200203 static std::map<std::string, PageSet*> mPageSets;
204 static PageSet* mCurrentSet;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100205 static MouseCursor *mMouseCursor;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100206 static HardwareKeyboard *mHardwareKeyboard;
Ethan Yonkere0f1f3b2015-10-27 09:49:01 -0500207 static bool mReloadTheme;
208 static std::string mStartPage;
that6a894592016-03-13 17:51:28 +0100209 static LoadingContext* currentLoadingContext;
Dees_Troy51a0e822012-09-05 15:24:24 -0400210};
211
Dees_Troye4a88112012-12-18 21:29:33 +0000212#endif // _PAGES_HEADER_HPP