skinparse.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. #ifndef __SKINPARSER_H
  2. #define __SKINPARSER_H
  3. #include <bfc/wasabi_std.h>
  4. #include <api/wnd/basewnd.h>
  5. #include <api/service/svccache.h>
  6. #ifdef WASABI_COMPILE_WNDMGR
  7. #include <api/wndmgr/layout.h>
  8. #include <api/wndmgr/container.h>
  9. #else
  10. class Container;
  11. class Layout;
  12. #endif
  13. #ifdef WASABI_COMPILE_FONTS
  14. #include <api/font/skinfont.h>
  15. #endif
  16. #ifdef WASABI_COMPILE_XMLPARSER
  17. #include <api/xml/xmlreader.h>
  18. #else
  19. class skin_xmlreaderparams;
  20. #endif
  21. #ifdef WASABI_COMPILE_SKIN
  22. #include <api/skin/group.h>
  23. #else
  24. class Group;
  25. class SkinItem;
  26. #endif
  27. class XmlObject;
  28. enum {
  29. PARSETYPE_RESIZE=0,
  30. PARSETYPE_COLOR,
  31. PARSETYPE_COLORALPHA,
  32. PARSETYPE_REGIONOP,
  33. PARSETYPE_INTERNALACTION,
  34. PARSETYPE_GROUPINHERITANCE,
  35. } ;
  36. enum {
  37. XML_TAG_CONTAINER,
  38. XML_TAG_GROUP,
  39. XML_TAG_CFGGROUP,
  40. XML_TAG_GROUPDEF,
  41. XML_TAG_LAYOUT,
  42. XML_TAG_ACCELERATORS,
  43. XML_TAG_ACCELERATOR,
  44. XML_TAG_ELEMENTS,
  45. XML_TAG_STRINGTABLE,
  46. XML_TAG_STRINGENTRY,
  47. XML_TAG_SCRIPTS,
  48. XML_TAG_SNAPPOINT,
  49. XML_TAG_TRUETYPEFONT,
  50. XML_TAG_BITMAPFONT,
  51. XML_TAG_SCRIPT,
  52. XML_TAG_UNKNOWN,
  53. };
  54. #define GROUP_INHERIT_NOTHING 0
  55. #define GROUP_INHERIT_XUIOBJECTS 1
  56. #define GROUP_INHERIT_SCRIPTS 2
  57. #define GROUP_INHERIT_PARAMS 4
  58. #define GROUP_INHERIT_ALL GROUP_INHERIT_XUIOBJECTS | GROUP_INHERIT_SCRIPTS | GROUP_INHERIT_PARAMS
  59. #define GROUP_INHERIT_ALLCONTENT GROUP_INHERIT_XUIOBJECTS | GROUP_INHERIT_SCRIPTS
  60. #define GROUP_GROUP 0
  61. #define GROUP_CFGGROUP 1
  62. #ifdef WASABI_COMPILE_WNDMGR
  63. #define GROUP_LAYOUTGROUP 2
  64. #endif
  65. enum {
  66. ACTION_NONE,
  67. ACTION_UNIMPLEMENTED=0x1000,
  68. ACTION_MINIMIZE,
  69. ACTION_MAXIMIZE,
  70. ACTION_CLOSE,
  71. ACTION_ABOUT,
  72. ACTION_SWITCH,
  73. ACTION_TOGGLE,
  74. ACTION_SYSMENU,
  75. ACTION_CONTROLMENU,
  76. ACTION_REPORT_BUGS,
  77. ACTION_MB_BACK, //FG
  78. ACTION_MB_FORWARD, //FG
  79. ACTION_MB_URL, //FG
  80. ACTION_MB_STOP, //FG
  81. ACTION_MB_REFRESH, //FG
  82. ACTION_MB_HOME, //FG
  83. ACTION_CB_NEXT, //FG
  84. ACTION_CB_PREV, //FG
  85. ACTION_CB_NEXTPAGE,
  86. ACTION_CB_PREVPAGE,
  87. ACTION_SCALE_50, //FG
  88. ACTION_SCALE_75, //FG
  89. ACTION_SCALE_100, //FG
  90. ACTION_SCALE_125, //FG
  91. ACTION_SCALE_150, //FG
  92. ACTION_SCALE_200, //FG
  93. ACTION_SCALE_400, //BU :)
  94. ACTION_RELOAD_SKIN,
  95. ACTION_TEXT_LARGER,
  96. ACTION_TEXT_SMALLER,
  97. ACTION_PREFERENCES,
  98. ACTION_REGISTRY,
  99. ACTION_ALPHA_10, //FG
  100. ACTION_ALPHA_20, //FG
  101. ACTION_ALPHA_30, //FG
  102. ACTION_ALPHA_40, //FG
  103. ACTION_ALPHA_50, //FG
  104. ACTION_ALPHA_60, //FG
  105. ACTION_ALPHA_70, //FG
  106. ACTION_ALPHA_80, //FG
  107. ACTION_ALPHA_90, //FG
  108. ACTION_ALPHA_100, //FG
  109. ACTION_AOT, //BU always-on-top for this window only
  110. ACTION_TOGGLE_ALWAYS_ON_TOP,
  111. ACTION_MENU,
  112. ACTION_VIEW_FILE_INFO,
  113. ACTION_ADD_BOOKMARK,
  114. ACTION_EDIT_BOOKMARKS,
  115. ACTION_ENDMODAL,
  116. ACTION_ENFORCEMINMAX,
  117. ACTION_DOUBLESIZE,
  118. ACTION_CLOSE_WINDOW,
  119. ACTION_WINDOWMENU,
  120. ACTION_EQ_TOGGLE,
  121. ACTION_AUTOOPACIFY,
  122. };
  123. enum {
  124. DISPLAY_NONE,
  125. DISPLAY_SONGNAME,
  126. DISPLAY_SONGINFO,
  127. DISPLAY_SONGTITLE, //BU
  128. DISPLAY_SONGARTIST,
  129. DISPLAY_SONGALBUM,
  130. DISPLAY_SONGLENGTH,
  131. DISPLAY_TIME,
  132. DISPLAY_CB, //FG
  133. DISPLAY_SONGBITRATE,
  134. DISPLAY_SONGSAMPLERATE,
  135. DISPLAY_SERVICE,
  136. DISPLAY_SONGINFO_TRANSLATED,
  137. };
  138. enum {
  139. ORIENTATION_HORIZONTAL,
  140. ORIENTATION_VERTICAL
  141. };
  142. enum {
  143. ALIGN_TOP,
  144. ALIGN_BOTTOM,
  145. };
  146. typedef struct
  147. {
  148. const wchar_t *tagname;
  149. int id;
  150. int needclosetag;
  151. } xml_tag;
  152. class XmlTagComp
  153. {
  154. public:
  155. static int compareItem(void *p1, void *p2)
  156. {
  157. return WCSICMP(((xml_tag *)p1)->tagname, ((xml_tag *)p2)->tagname);
  158. }
  159. static int compareAttrib(const wchar_t *attrib, void *item)
  160. {
  161. return WCSICMP(attrib, ((xml_tag *)item)->tagname);
  162. }
  163. };
  164. typedef struct {
  165. int staticloading;
  166. int recording_container;
  167. int recording_groupdef;
  168. Group *curGroup;
  169. int inElements;
  170. int inAccelerators;
  171. int inStringTable;
  172. int inGroupDef;
  173. int inGroup;
  174. StringW includepath;
  175. skin_xmlreaderparams *groupparams;
  176. int instantiatinggroup;
  177. int scriptid;
  178. int allowscripts;
  179. #ifdef WASABI_COMPILE_WNDMGR
  180. Container *curContainer;
  181. Layout *curLayout;
  182. int inContainer;
  183. int inLayout;
  184. int transcientcontainer;
  185. #endif
  186. } parser_status;
  187. class SkinParser {
  188. public:
  189. static void initialize();
  190. static void shutdown();
  191. static void setInitialFocus();
  192. static GuiObject *newDynamicGroup(const wchar_t *groupid, int grouptype=GROUP_GROUP, SkinItem *item=NULL, int specific_scriptid=-1, int scripts_enabled=1);
  193. static void parseGroup(SkinItem *groupitem, PtrList<ifc_xmlreaderparams> *ancestor_param_list, int params_only=0, int content_flags=GROUP_INHERIT_ALL);
  194. static void loadScriptXml(const wchar_t *filename, int scriptid);
  195. static void xmlReaderCallback(int start, const wchar_t *xmltag, skin_xmlreaderparams *params);
  196. static void onXmlStartElement(const wchar_t *name, skin_xmlreaderparams *params);
  197. static void onXmlEndElement(const wchar_t *name);
  198. static void _onXmlStartElement(int object_type, const wchar_t *object_name, ifc_xmlreaderparams *params);
  199. static void _onXmlEndElement(int object_type, const wchar_t *object_name);
  200. #ifdef WASABI_COMPILE_WNDMGR
  201. static GUID *getComponentGuid(const wchar_t *id);
  202. static int getComponentGuid(GUID *g, const wchar_t *p);
  203. #endif
  204. #ifdef WASABI_COMPILE_WNDMGR
  205. static int loadContainers(const wchar_t *skin); // todo: change name
  206. static void startupContainers(int scriptid=-1); // todo: change name
  207. static Container *loadContainerForWindowHolder(const wchar_t *groupid=NULL, GUID g=INVALID_GUID, int initit=1, int transcient=0, const wchar_t *containerid=NULL/*any*/, int container_flag=0/*dontcare*/);
  208. static Container *newDynamicContainer(const wchar_t *containerid, int transcient=0);
  209. static Container *getContainer(const wchar_t *name);
  210. static Layout *getLayout(const wchar_t *container_layout_pair);
  211. static Container *script_getContainer(const wchar_t *name);
  212. static Container *instantiateDynamicContainer(SkinItem *containeritem, int initit=1);
  213. static void componentToggled(GUID *g, int visible);
  214. static void sendNotifyToAllContainers(int notifymsg, int param1=0, int param2=0);
  215. static void toggleContainer(const wchar_t *);
  216. static void toggleContainer(int);
  217. static void showContainer(int num, int show);
  218. static void showContainer(const wchar_t *, int show);
  219. static PtrList<Container> containers;
  220. //static PtrList<Container> script_containers;
  221. static int getNumContainers();
  222. static Container *enumContainer(int n);
  223. static int script_getNumContainers();
  224. static Container *script_enumContainer(int id);
  225. static int isContainer(Container *c);
  226. static int verifyContainer(Container *);
  227. static void unloadAllContainers();
  228. static const wchar_t *getCurrentContainerId();
  229. #endif
  230. static void cleanupScript(int scriptid);
  231. static void cleanUp();
  232. #ifdef WA3COMPATIBILITY
  233. static void emmergencyReloadDefaultSkin();
  234. #endif
  235. static void initGuiObject(GuiObject *o, Group *pgroup);
  236. static void initXmlObject(XmlObject *x, ifc_xmlreaderparams *params, int no_id=0);
  237. static void initLayout(Layout *l, Container *c);
  238. static int getAction(const wchar_t *action, const wchar_t **name=NULL);
  239. static int getDisplay(const wchar_t *display);
  240. static int getAlign(const wchar_t *align);
  241. static int getOrientation(const wchar_t *orient);
  242. static int parse(const wchar_t *str, const wchar_t *how);
  243. static int parseResize(const wchar_t *r);
  244. static int parseRegionOp(const wchar_t *r);
  245. static int parseGroupInheritance(const wchar_t *str);
  246. static ARGB32 parseColor(const wchar_t *color, int *error=NULL); // 1 for bitmap colors please
  247. static ARGB32 parseColorAlpha(const wchar_t *color); // 1 for bitmap colors please
  248. static const wchar_t *getXmlRootPath();
  249. static void pushParserState();
  250. static void popParserState();
  251. #ifdef WASABI_COMPILE_WNDMGR
  252. static void noCenterSkin() { centerskin=0; }
  253. #endif
  254. static const wchar_t *getCurrentGroupId();
  255. static void destroyGuiObject(GuiObject *o);
  256. static void fillGroup(Group *group, const wchar_t *groupid, SkinItem *specific_item=NULL, int params_only=0, int no_params=0, int scripts_enabled=1);
  257. static int getSkinRect(RECT *r, ifc_window *exclude=NULL);
  258. static void centerSkin();
  259. static void focusFirst();
  260. static GuiObject *xui_new(const wchar_t *classname);
  261. static void xui_delete(GuiObject *o);
  262. static double getSkinVersion();
  263. static void setAllLayoutsRatio(double ra);
  264. static void setAllLayoutsTransparency(int v);
  265. // static void setAllLayoutsAutoOpacify(int v, int force=0);
  266. // static void setAllLayoutsOverrideAlpha(int oa);
  267. static Layout *getMainLayout();
  268. private:
  269. static GuiObject *createExternalGuiObject(const wchar_t *object_name, XmlObject **x, ifc_xmlreaderparams *params);
  270. static int getHex(const wchar_t *p,int size=-1);
  271. // xml parser handlers
  272. static Group *curGroup, *lastCreatedGroup;
  273. static int inScripts;
  274. static int inElements, inAccelerators, inStringTable;
  275. static int inGroupDef, inGroup;
  276. static StringW includepath;
  277. static int recording_container;
  278. static int recording_groupdef;
  279. static int staticloading;
  280. static PtrList<parser_status> statusstack;
  281. static int instantiatinggroup;
  282. static int scriptId;
  283. static int allowscripts;
  284. static skin_xmlreaderparams *groupparams;
  285. #ifdef WASABI_COMPILE_WNDMGR
  286. static Container *curContainer, *lastCreatedContainer;
  287. static Layout *curLayout;
  288. static int centerskin;
  289. static int transcientcontainer;
  290. static int inContainer;
  291. static int inLayout;
  292. #endif
  293. static double skinversion;
  294. static int loading_main_skinfile;
  295. static PtrListQuickSorted<xml_tag,XmlTagComp> quickxmltaglist;
  296. static SvcCacheT<svc_xuiObject> *xuiCache;
  297. };
  298. #endif