api_language.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. #ifndef NULLSOFT_API_LANGUAGE_H
  2. #define NULLSOFT_API_LANGUAGE_H
  3. #include "../../bfc/dispatch.h"
  4. #include "lang.h"
  5. #include <locale.h>
  6. #if (_MSC_VER <= 1200)
  7. struct threadlocaleinfostruct;
  8. struct threadmbcinfostruct;
  9. typedef struct threadlocaleinfostruct * pthreadlocinfo;
  10. typedef struct threadmbcinfostruct * pthreadmbcinfo;
  11. typedef struct localeinfo_struct
  12. {
  13. pthreadlocinfo locinfo;
  14. pthreadmbcinfo mbcinfo;
  15. } _locale_tstruct, *_locale_t;
  16. #endif
  17. class api_language : public Dispatchable
  18. {
  19. protected:
  20. api_language() {}
  21. ~api_language() {}
  22. public:
  23. char *GetString(HINSTANCE hinst, HINSTANCE owner, UINT uID, char *str=NULL, size_t maxlen=0);
  24. wchar_t *GetStringW(HINSTANCE hinst, HINSTANCE owner, UINT uID, wchar_t *str=NULL, size_t maxlen=0);
  25. char *GetStringFromGUID(const GUID guid, HINSTANCE owner, UINT uID, char *str=NULL, size_t maxlen=0);
  26. wchar_t *GetStringFromGUIDW(const GUID guid, HINSTANCE owner, UINT uID, wchar_t *str=NULL, size_t maxlen=0);
  27. HINSTANCE FindDllHandleByGUID(GUID guid);
  28. HINSTANCE FindDllHandleByString(const char* str);
  29. HINSTANCE FindDllHandleByStringW(const wchar_t* str);
  30. HINSTANCE StartLanguageSupport(HINSTANCE hinstance, const GUID guid);
  31. const wchar_t *GetLanguageFolder();
  32. #define LANG_IDENT_STR 0
  33. #define LANG_LANG_CODE 1
  34. #define LANG_COUNTRY_CODE 2
  35. const wchar_t *GetLanguageIdentifier(int mode);
  36. HWND CreateLDialogParam(HINSTANCE localised, HINSTANCE original, UINT id, HWND parent, DLGPROC proc, LPARAM param);
  37. INT_PTR LDialogBoxParam(HINSTANCE localised, HINSTANCE original, UINT id, HWND parent, DLGPROC proc, LPARAM param);
  38. HMENU LoadLMenu(HINSTANCE localised, HINSTANCE original, UINT id);
  39. HWND CreateLDialogParamW(HINSTANCE localised, HINSTANCE original, UINT id, HWND parent, DLGPROC proc, LPARAM param);
  40. INT_PTR LDialogBoxParamW(HINSTANCE localised, HINSTANCE original, UINT id, HWND parent, DLGPROC proc, LPARAM param);
  41. HMENU LoadLMenuW(HINSTANCE localised, HINSTANCE original, UINT id);
  42. void* LoadResourceFromFile(HINSTANCE hinst, HINSTANCE owner, LPCTSTR lpType, LPCTSTR lpName, DWORD* size);
  43. void* LoadResourceFromFileW(HINSTANCE hinst, HINSTANCE owner, LPCWSTR lpType, LPCWSTR lpName, DWORD* size);
  44. HACCEL LoadAcceleratorsA(HINSTANCE hinst, HINSTANCE owner, LPCSTR lpTableName);
  45. HACCEL LoadAcceleratorsW(HINSTANCE hinst, HINSTANCE owner, LPCWSTR lpTableName);
  46. // Implemented in 5.58+
  47. // When called this will attempt to set the locale used for numeric representation
  48. // to that of the user running the current Winamp instance as long as the language
  49. // and country identifiers match those reported within the language pack (if used)
  50. //
  51. // If you're running under a different thread then this will need to be called as
  52. // the locale is set on a per thread basis which generally means anything under the
  53. // Winamp process will be handled correctly unless a UI aspect is running under a
  54. // different thread. Internally this is called within winamp.exe and vis_milk2.dll
  55. BOOL UseUserNumericLocale();
  56. // Get_C_NumericLocale() is a wrapper for _create_locale(LC_NUMERIC, "C") which can
  57. // then be used in _atof_l(..), _sscanf_l(..) or other locale based functions when
  58. // you need to process numbers without localisation handling ie the "C" locale.
  59. // This function is provided for convenience unless you want to do it all manually.
  60. _locale_t Get_C_NumericLocale();
  61. public:
  62. DISPATCH_CODES
  63. {
  64. API_LANGUAGE_GETSTRING = 10,
  65. API_LANGUAGE_GETSTRINGW = 11,
  66. API_LANGUAGE_GETSTRINGFROMGUID = 12,
  67. API_LANGUAGE_GETSTRINGFROMGUIDW = 13,
  68. API_LANGUAGE_GETHINSTANCEBYGUID = 20,
  69. API_LANGUAGE_GETHINSTANCEBYNAME = 21,
  70. API_LANGUAGE_GETHINSTANCEBYNAMEW = 22,
  71. API_LANGUAGE_STARTUP = 30,
  72. API_LANGUAGE_SHUTDOWN = 31,
  73. API_LANGUAGE_GETLANGUAGEFOLDER=40,
  74. API_LANGUAGE_CREATELDIALOGPARAM=50,
  75. API_LANGUAGE_LDIALOGBOXPARAM=51,
  76. API_LANGUAGE_LOADLMENU=52,
  77. API_LANGUAGE_CREATELDIALOGPARAMW=53,
  78. API_LANGUAGE_LDIALOGBOXPARAMW=54,
  79. API_LANGUAGE_LOADLMENUW=55,
  80. API_LANGUAGE_GETLANGUAGEIDENTIFIER=60,
  81. API_LANGUAGE_LOADRESOURCEFROMFILE=70,
  82. API_LANGUAGE_LOADRESOURCEFROMFILEW=71,
  83. API_LANGUAGE_LOADACCELERATORSA=80,
  84. API_LANGUAGE_LOADACCELERATORSW=81,
  85. // Implemented in 5.58+
  86. // See UseUserNumericLocale notes
  87. API_LANGUAGE_USEUSERNUMERICLOCALE=90,
  88. API_LANGUAGE_GET_C_NUMERICLOCALE=91,
  89. };
  90. };
  91. inline char *api_language::GetString(HINSTANCE hinst, HINSTANCE owner, UINT uID, char *str, size_t maxlen)
  92. {
  93. return _call(API_LANGUAGE_GETSTRING, (char * )0, hinst, owner, uID, str, maxlen);
  94. }
  95. inline wchar_t *api_language::GetStringW(HINSTANCE hinst, HINSTANCE owner, UINT uID, wchar_t *str, size_t maxlen)
  96. {
  97. return _call(API_LANGUAGE_GETSTRINGW, (wchar_t * )0, hinst, owner, uID, str, maxlen);
  98. }
  99. inline char *api_language::GetStringFromGUID(const GUID guid, HINSTANCE owner, UINT uID, char *str, size_t maxlen)
  100. {
  101. return _call(API_LANGUAGE_GETSTRINGFROMGUID, (char * )0, guid, owner, uID, str, maxlen);
  102. }
  103. inline wchar_t *api_language::GetStringFromGUIDW(const GUID guid, HINSTANCE owner, UINT uID, wchar_t *str, size_t maxlen)
  104. {
  105. return _call(API_LANGUAGE_GETSTRINGFROMGUIDW, (wchar_t * )0, guid, owner, uID, str, maxlen);
  106. }
  107. inline HINSTANCE api_language::FindDllHandleByGUID(const GUID guid)
  108. {
  109. return _call(API_LANGUAGE_GETHINSTANCEBYGUID, (HINSTANCE )0, guid);
  110. }
  111. inline HINSTANCE api_language::FindDllHandleByString(const char* str)
  112. {
  113. return _call(API_LANGUAGE_GETHINSTANCEBYNAME, (HINSTANCE )0, str);
  114. }
  115. inline HINSTANCE api_language::FindDllHandleByStringW(const wchar_t* str)
  116. {
  117. return _call(API_LANGUAGE_GETHINSTANCEBYNAMEW, (HINSTANCE )0, str);
  118. }
  119. inline HINSTANCE api_language::StartLanguageSupport(HINSTANCE hinstance, const GUID guid)
  120. {
  121. return _call(API_LANGUAGE_STARTUP, (HINSTANCE )0, hinstance, guid);
  122. }
  123. inline const wchar_t *api_language::GetLanguageFolder()
  124. {
  125. return _call(API_LANGUAGE_GETLANGUAGEFOLDER, (const wchar_t *)0);
  126. }
  127. inline HWND api_language::CreateLDialogParam(HINSTANCE localised, HINSTANCE original, UINT id, HWND parent, DLGPROC proc, LPARAM param)
  128. {
  129. return _call(API_LANGUAGE_CREATELDIALOGPARAM, (HWND)0, localised, original, id, parent, proc, param);
  130. }
  131. inline INT_PTR api_language::LDialogBoxParam(HINSTANCE localised, HINSTANCE original, UINT id, HWND parent, DLGPROC proc, LPARAM param)
  132. {
  133. return _call(API_LANGUAGE_LDIALOGBOXPARAM, (INT_PTR)0, localised, original, id, parent, proc, param);
  134. }
  135. inline HMENU api_language::LoadLMenu(HINSTANCE localised, HINSTANCE original, UINT id)
  136. {
  137. return _call(API_LANGUAGE_LOADLMENU, (HMENU)0, localised, original, id);
  138. }
  139. inline HWND api_language::CreateLDialogParamW(HINSTANCE localised, HINSTANCE original, UINT id, HWND parent, DLGPROC proc, LPARAM param)
  140. {
  141. return _call(API_LANGUAGE_CREATELDIALOGPARAMW, (HWND)0, localised, original, id, parent, proc, param);
  142. }
  143. inline INT_PTR api_language::LDialogBoxParamW(HINSTANCE localised, HINSTANCE original, UINT id, HWND parent, DLGPROC proc, LPARAM param)
  144. {
  145. return _call(API_LANGUAGE_LDIALOGBOXPARAMW, (INT_PTR)0, localised, original, id, parent, proc, param);
  146. }
  147. inline HMENU api_language::LoadLMenuW(HINSTANCE localised, HINSTANCE original, UINT id)
  148. {
  149. return _call(API_LANGUAGE_LOADLMENUW, (HMENU)0, localised, original, id);
  150. }
  151. inline const wchar_t *api_language::GetLanguageIdentifier(int mode)
  152. {
  153. return _call(API_LANGUAGE_GETLANGUAGEIDENTIFIER, (const wchar_t *)0, mode);
  154. }
  155. inline void *api_language::LoadResourceFromFile(HINSTANCE hinst, HINSTANCE owner, LPCTSTR lpType, LPCTSTR lpName, DWORD* size)
  156. {
  157. return _call(API_LANGUAGE_LOADRESOURCEFROMFILE, (void*)0, hinst, owner, lpType, lpName, size);
  158. }
  159. inline void *api_language::LoadResourceFromFileW(HINSTANCE hinst, HINSTANCE owner, LPCWSTR lpType, LPCWSTR lpName, DWORD* size)
  160. {
  161. return _call(API_LANGUAGE_LOADRESOURCEFROMFILEW, (void*)0, hinst, owner, lpType, lpName, size);
  162. }
  163. inline HACCEL api_language::LoadAcceleratorsA(HINSTANCE hinst, HINSTANCE owner, LPCSTR lpTableName)
  164. {
  165. return _call(API_LANGUAGE_LOADACCELERATORSA, (HACCEL)NULL, hinst, owner, lpTableName);
  166. }
  167. inline HACCEL api_language::LoadAcceleratorsW(HINSTANCE hinst, HINSTANCE owner, LPCWSTR lpTableName)
  168. {
  169. return _call(API_LANGUAGE_LOADACCELERATORSA, (HACCEL)NULL, hinst, owner, lpTableName);
  170. }
  171. inline BOOL api_language::UseUserNumericLocale()
  172. {
  173. return _call(API_LANGUAGE_USEUSERNUMERICLOCALE, (BOOL)0);
  174. }
  175. inline _locale_t api_language::Get_C_NumericLocale()
  176. {
  177. return _call(API_LANGUAGE_GET_C_NUMERICLOCALE, (_locale_t)0);
  178. }
  179. // utility macros and relevant predefined variables for use with the service + macros
  180. extern api_language *languageManager;
  181. #define WASABI_API_LNG languageManager
  182. extern HINSTANCE api_localised_hinstance;
  183. #define WASABI_API_LNG_HINST api_localised_hinstance
  184. extern HINSTANCE api_orig_hinstance;
  185. #define WASABI_API_ORIG_HINST api_orig_hinstance
  186. #define WASABI_API_LNGSTR WASABI_API_LNG->GetString
  187. // use this is you want a temp copy of the string
  188. #define WASABI_API_LNGSTRING(uID) \
  189. WASABI_API_LNGSTR(WASABI_API_LNG_HINST,WASABI_API_ORIG_HINST,uID)
  190. // use this is you want a temp copy of the string but need it to fallback to a different module
  191. #define WASABI_API_LNGSTRING_HINST(hinst,uID) \
  192. WASABI_API_LNGSTR(WASABI_API_LNG_HINST,hinst,uID)
  193. // use this is you want a copy of the string
  194. #define WASABI_API_LNGSTRING_BUF(uID,buf,len) \
  195. WASABI_API_LNGSTR(WASABI_API_LNG_HINST,WASABI_API_ORIG_HINST,uID,buf,len)
  196. // use this is you want a copy of the string but need it to fallback to a different module
  197. #define WASABI_API_LNGSTRING_HINST_BUF(hinst,uID,buf,len) \
  198. WASABI_API_LNGSTR(WASABI_API_LNG_HINST,hinst,uID,buf,len)
  199. // unicode versions of the above macros
  200. #define WASABI_API_LNGSTRW WASABI_API_LNG->GetStringW
  201. #define WASABI_API_LNGSTRINGW(uID) \
  202. WASABI_API_LNGSTRW(WASABI_API_LNG_HINST,WASABI_API_ORIG_HINST,uID)
  203. #define WASABI_API_LNGSTRINGW_HINST(hinst,uID) \
  204. WASABI_API_LNGSTRW(WASABI_API_LNG_HINST,hinst,uID)
  205. #define WASABI_API_LNGSTRINGW_BUF(uID,buf,len) \
  206. WASABI_API_LNGSTRW(WASABI_API_LNG_HINST,WASABI_API_ORIG_HINST,uID,buf,len)
  207. #define WASABI_API_LNGSTRINGW_BUF_HINST(hinst,uID,buf,len) \
  208. WASABI_API_LNGSTRW(WASABI_API_LNG_HINST,hinst,uID,buf,len)
  209. // Dialog handling functions (will revert back to the non-localised version if not valid/present)
  210. #define WASABI_API_CREATEDIALOGPARAM(id, parent, proc, param) \
  211. WASABI_API_LNG->CreateLDialogParam(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, id, parent, (DLGPROC)proc, param)
  212. #define WASABI_API_CREATEDIALOG(id, parent, proc) \
  213. WASABI_API_LNG->CreateLDialogParam(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, id, parent, (DLGPROC)proc, 0)
  214. #define WASABI_API_CREATEDIALOGPARAMW(id, parent, proc, param) \
  215. WASABI_API_LNG->CreateLDialogParamW(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, id, parent, (DLGPROC)proc, param)
  216. #define WASABI_API_CREATEDIALOGW(id, parent, proc) \
  217. WASABI_API_LNG->CreateLDialogParamW(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, id, parent, (DLGPROC)proc, 0)
  218. #define WASABI_API_DIALOGBOXPARAM(id, parent, proc, param) \
  219. WASABI_API_LNG->LDialogBoxParam(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, id, parent, (DLGPROC)proc, param)
  220. #define WASABI_API_DIALOGBOX(id, parent, proc) \
  221. WASABI_API_LNG->LDialogBoxParam(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, id, parent, (DLGPROC)proc, 0)
  222. #define WASABI_API_DIALOGBOXPARAMW(id, parent, proc, param) \
  223. WASABI_API_LNG->LDialogBoxParamW(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, id, parent, (DLGPROC)proc, param)
  224. #define WASABI_API_DIALOGBOXW(id, parent, proc) \
  225. WASABI_API_LNG->LDialogBoxParamW(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, id, parent, (DLGPROC)proc, 0)
  226. #define WASABI_API_LOADMENU(id) \
  227. WASABI_API_LNG->LoadLMenu(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, id)
  228. #define WASABI_API_LOADMENUW(id) \
  229. WASABI_API_LNG->LoadLMenuW(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, id)
  230. #define WASABI_API_LOADACCELERATORSA(__id) \
  231. WASABI_API_LNG->LoadAcceleratorsA(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, MAKEINTRESOURCEA(__id))
  232. #define WASABI_API_LOADACCELERATORSW(__id) \
  233. WASABI_API_LNG->LoadAcceleratorsW(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, MAKEINTRESOURCEW(__id))
  234. #ifdef UNICODE
  235. #define WASABI_API_LOADACCELERATORS WASABI_API_LOADACCELERATORSW
  236. #else
  237. #define WASABI_API_LOADACCELERATORS WASABI_API_LOADACCELERATORSA
  238. #endif
  239. #define WASABI_API_START_LANG(orig_hinst, guid) \
  240. { \
  241. WASABI_API_ORIG_HINST = orig_hinst; \
  242. WASABI_API_LNG_HINST = WASABI_API_LNG->StartLanguageSupport(WASABI_API_ORIG_HINST,guid); \
  243. }
  244. #define WASABI_API_LOADRESFROMFILE(lpType, lpName, size) \
  245. WASABI_API_LNG->LoadResourceFromFile(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, lpType, lpName, size)
  246. #define WASABI_API_LOADRESFROMFILEW(lpType, lpName, size) \
  247. WASABI_API_LNG->LoadResourceFromFileW(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, lpType, lpName, size)
  248. // {30AED4E5-EF10-4277-8D49-27AB5570E891}
  249. static const GUID languageApiGUID =
  250. { 0x30aed4e5, 0xef10, 0x4277, { 0x8d, 0x49, 0x27, 0xab, 0x55, 0x70, 0xe8, 0x91 } };
  251. #endif