1
0

localesmgr.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #ifndef _LOCALESMGR_H
  2. #define _LOCALESMGR_H
  3. #include "../xml/obj_xml.h"
  4. #include <bfc/ptrlist.h>
  5. #include <bfc/string/bfcstring.h>
  6. #include <api/skin/skinparse.h>
  7. #include "LocalesInfo.h"
  8. class LocTrans
  9. {
  10. public:
  11. LocTrans(const wchar_t *pfrom, const wchar_t *pto) : from(pfrom), to(pto)
  12. {
  13. //from.toupper();
  14. }
  15. const wchar_t *getFrom() { return from; }
  16. const wchar_t *getTo() { return to; }
  17. private:
  18. StringW from;
  19. StringW to;
  20. };
  21. class PLS_LocTrans
  22. {
  23. public:
  24. // comparator for sorting
  25. static int compareItem(LocTrans *p1, LocTrans* p2) {
  26. return wcscmp(p1->getFrom(), p2->getFrom());
  27. }
  28. // comparator for searching
  29. static int compareAttrib(const wchar_t *attrib, LocTrans *item) {
  30. return wcscmp(attrib, item->getFrom());
  31. }
  32. };
  33. class LocAccel
  34. {
  35. public:
  36. LocAccel(const wchar_t *psec, const wchar_t *pkey, const wchar_t *paction)
  37. : section(psec), key(pkey), realkey(pkey), action(paction)
  38. {
  39. key.tolower();
  40. actionnum = SkinParser::getAction(paction);
  41. }
  42. const wchar_t *getKey() { return key; }
  43. const wchar_t *getRealKey() { return realkey; }
  44. const wchar_t *getAction() { return action; }
  45. int getActionNum() { return actionnum; }
  46. const wchar_t *getSection() { return section; }
  47. private:
  48. StringW section;
  49. StringW key;
  50. StringW realkey;
  51. StringW action;
  52. int actionnum;
  53. };
  54. class PLS_LocAccel
  55. {
  56. public:
  57. // comparator for sorting
  58. static int compareItem(LocAccel *p1, LocAccel *p2)
  59. {
  60. return wcscmp(p1->getKey(), p2->getKey());
  61. }
  62. // comparator for searching
  63. static int compareAttrib(const wchar_t *attrib, LocAccel *item)
  64. {
  65. return wcscmp(attrib, item->getKey());
  66. }
  67. };
  68. class LocalesAcceleratorSectionXmlCallback : public ifc_xmlreadercallbackI
  69. {
  70. void xmlReaderOnStartElementCallback(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params);
  71. void xmlReaderOnEndElementCallback(const wchar_t *xmlpath, const wchar_t *xmltag);
  72. };
  73. class LocalesAcceleratorXmlCallback : public ifc_xmlreadercallbackI
  74. {
  75. void xmlReaderOnStartElementCallback(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params);
  76. };
  77. class LocalesTranslationXmlCallback : public ifc_xmlreadercallbackI
  78. {
  79. void xmlReaderOnStartElementCallback(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params);
  80. };
  81. class StringTableXmlCallback : public ifc_xmlreadercallbackI
  82. {
  83. void xmlReaderOnStartElementCallback(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params);
  84. void xmlReaderOnEndElementCallback(const wchar_t *xmlpath, const wchar_t *xmltag);
  85. };
  86. class StringTableEntryXmlCallback : public ifc_xmlreadercallbackI
  87. {
  88. void xmlReaderOnStartElementCallback(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params);
  89. };
  90. class LocalesSkinCallback : public SkinCallbackI
  91. {
  92. public:
  93. int skincb_onUnloading();
  94. int skincb_onReset();
  95. int skincb_onReload();
  96. int skincb_onBeforeLoadingElements();
  97. int skincb_onGuiLoaded();
  98. int skincb_onLoaded();
  99. };
  100. class LocalesManager
  101. {
  102. public:
  103. static void init();
  104. static void load();
  105. static void deinit();
  106. static void loadFile(const wchar_t *name);
  107. static void addTranslation(const wchar_t *from, const wchar_t *to);
  108. static const wchar_t *getTranslation(const wchar_t *from); // will return the from parameter if not found
  109. static const wchar_t *lookupString(const wchar_t *from); // will return the from parameter if not found
  110. static void setAcceleratorSection(const wchar_t *section);
  111. static void addAccelerator(const wchar_t *bind, const wchar_t *action);
  112. static void addAcceleratorFromSkin(const wchar_t *bind, const wchar_t *action);
  113. static const wchar_t *getBindFromAction(int action);
  114. static const wchar_t *translateAccelerator(const wchar_t *section, const wchar_t *key);
  115. //static const wchar_t *enumLoadableLocales(int num);
  116. //static int getNumLocales();
  117. //static void setNewLocaleFile(const wchar_t *name);
  118. //static void setNewLocaleNum(int num);
  119. //static int isCurrentLocaleNum(int num) { return num == curLocaleNum; }
  120. static void resetAll();
  121. static const wchar_t *getLocaleRoot();
  122. static void LoadStringTables();
  123. static void LoadStringTable(const wchar_t *filename);
  124. static void SetStringTable(const wchar_t *table);
  125. static void ResetStrings();
  126. static const wchar_t *GetString(const wchar_t *table, uint32_t id);
  127. static void AddString(const wchar_t *table, uint32_t id, const wchar_t *string);
  128. static void AddString(uint32_t id, const wchar_t *string);
  129. private:
  130. static LocalesAcceleratorXmlCallback accelXmlCallback;
  131. static LocalesAcceleratorSectionXmlCallback accelSectionXmlCallback;
  132. static LocalesTranslationXmlCallback transXmlCallback;
  133. static PtrListSorted<LocTrans, PLS_LocTrans, QuickSorted<LocTrans, PLS_LocTrans> > translationsList;
  134. static PtrListSorted<LocAccel, PLS_LocAccel, QuickSorted<LocAccel, PLS_LocAccel> > acceleratorsList;
  135. static StringW localePath;
  136. //static PtrList<LocaleItem> loadableLocalesList;
  137. //static int localeListLoaded, curLocaleNum, englishLocale;
  138. static StringW curSection;
  139. static StringW curTable;
  140. static LocalesSkinCallback localesSkinCallback;
  141. static StringTableXmlCallback stringTableXmlCallback;
  142. static StringTableEntryXmlCallback stringTableXmlEntryCallback;
  143. };
  144. #endif//_LOCALESMGR_H