1
0

api_language.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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* LoadResourceFromFileA(HINSTANCE hinst, HINSTANCE owner, LPCSTR lpType, LPCSTR 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. // Implemented in 5.64+
  62. wchar_t* FormattedSizeString(wchar_t *out, int cchLen, __int64 size);
  63. public:
  64. DISPATCH_CODES
  65. {
  66. API_LANGUAGE_GETSTRING = 10,
  67. API_LANGUAGE_GETSTRINGW = 11,
  68. API_LANGUAGE_GETSTRINGFROMGUID = 12,
  69. API_LANGUAGE_GETSTRINGFROMGUIDW = 13,
  70. API_LANGUAGE_GETHINSTANCEBYGUID = 20,
  71. API_LANGUAGE_GETHINSTANCEBYNAME = 21,
  72. API_LANGUAGE_GETHINSTANCEBYNAMEW = 22,
  73. API_LANGUAGE_STARTUP = 30,
  74. API_LANGUAGE_SHUTDOWN = 31,
  75. API_LANGUAGE_GETLANGUAGEFOLDER = 40,
  76. API_LANGUAGE_CREATELDIALOGPARAM = 50,
  77. API_LANGUAGE_LDIALOGBOXPARAM = 51,
  78. API_LANGUAGE_LOADLMENU = 52,
  79. API_LANGUAGE_CREATELDIALOGPARAMW = 53,
  80. API_LANGUAGE_LDIALOGBOXPARAMW = 54,
  81. API_LANGUAGE_LOADLMENUW = 55,
  82. API_LANGUAGE_GETLANGUAGEIDENTIFIER = 60,
  83. API_LANGUAGE_LOADRESOURCEFROMFILEA = 70,
  84. API_LANGUAGE_LOADRESOURCEFROMFILEW = 71,
  85. API_LANGUAGE_LOADACCELERATORSA = 80,
  86. API_LANGUAGE_LOADACCELERATORSW = 81,
  87. // Implemented in 5.58+
  88. // See UseUserNumericLocale notes
  89. API_LANGUAGE_USEUSERNUMERICLOCALE = 90,
  90. API_LANGUAGE_GET_C_NUMERICLOCALE = 91,
  91. // Implemented in 5.64+
  92. API_LANGUAGE_FORMATTEDSIZESTRING = 100,
  93. };
  94. };
  95. inline char *api_language::GetString(HINSTANCE hinst, HINSTANCE owner, UINT uID, char *str, size_t maxlen)
  96. {
  97. return _call(API_LANGUAGE_GETSTRING, (char * )0, hinst, owner, uID, str, maxlen);
  98. }
  99. inline wchar_t *api_language::GetStringW(HINSTANCE hinst, HINSTANCE owner, UINT uID, wchar_t *str, size_t maxlen)
  100. {
  101. return _call(API_LANGUAGE_GETSTRINGW, (wchar_t * )0, hinst, owner, uID, str, maxlen);
  102. }
  103. inline char *api_language::GetStringFromGUID(const GUID guid, HINSTANCE owner, UINT uID, char *str, size_t maxlen)
  104. {
  105. return _call(API_LANGUAGE_GETSTRINGFROMGUID, (char * )0, guid, owner, uID, str, maxlen);
  106. }
  107. inline wchar_t *api_language::GetStringFromGUIDW(const GUID guid, HINSTANCE owner, UINT uID, wchar_t *str, size_t maxlen)
  108. {
  109. return _call(API_LANGUAGE_GETSTRINGFROMGUIDW, (wchar_t * )0, guid, owner, uID, str, maxlen);
  110. }
  111. inline HINSTANCE api_language::FindDllHandleByGUID(const GUID guid)
  112. {
  113. return _call(API_LANGUAGE_GETHINSTANCEBYGUID, (HINSTANCE )0, guid);
  114. }
  115. inline HINSTANCE api_language::FindDllHandleByString(const char* str)
  116. {
  117. return _call(API_LANGUAGE_GETHINSTANCEBYNAME, (HINSTANCE )0, str);
  118. }
  119. inline HINSTANCE api_language::FindDllHandleByStringW(const wchar_t* str)
  120. {
  121. return _call(API_LANGUAGE_GETHINSTANCEBYNAMEW, (HINSTANCE )0, str);
  122. }
  123. inline HINSTANCE api_language::StartLanguageSupport(HINSTANCE hinstance, const GUID guid)
  124. {
  125. return _call(API_LANGUAGE_STARTUP, (HINSTANCE )0, hinstance, guid);
  126. }
  127. inline const wchar_t *api_language::GetLanguageFolder()
  128. {
  129. return _call(API_LANGUAGE_GETLANGUAGEFOLDER, (const wchar_t *)0);
  130. }
  131. inline HWND api_language::CreateLDialogParam(HINSTANCE localised, HINSTANCE original, UINT id, HWND parent, DLGPROC proc, LPARAM param)
  132. {
  133. return _call(API_LANGUAGE_CREATELDIALOGPARAM, (HWND)0, localised, original, id, parent, proc, param);
  134. }
  135. inline INT_PTR api_language::LDialogBoxParam(HINSTANCE localised, HINSTANCE original, UINT id, HWND parent, DLGPROC proc, LPARAM param)
  136. {
  137. return _call(API_LANGUAGE_LDIALOGBOXPARAM, (INT_PTR)0, localised, original, id, parent, proc, param);
  138. }
  139. inline HMENU api_language::LoadLMenu(HINSTANCE localised, HINSTANCE original, UINT id)
  140. {
  141. return _call(API_LANGUAGE_LOADLMENU, (HMENU)0, localised, original, id);
  142. }
  143. inline HWND api_language::CreateLDialogParamW(HINSTANCE localised, HINSTANCE original, UINT id, HWND parent, DLGPROC proc, LPARAM param)
  144. {
  145. return _call(API_LANGUAGE_CREATELDIALOGPARAMW, (HWND)0, localised, original, id, parent, proc, param);
  146. }
  147. inline INT_PTR api_language::LDialogBoxParamW(HINSTANCE localised, HINSTANCE original, UINT id, HWND parent, DLGPROC proc, LPARAM param)
  148. {
  149. return _call(API_LANGUAGE_LDIALOGBOXPARAMW, (INT_PTR)0, localised, original, id, parent, proc, param);
  150. }
  151. inline HMENU api_language::LoadLMenuW(HINSTANCE localised, HINSTANCE original, UINT id)
  152. {
  153. return _call(API_LANGUAGE_LOADLMENUW, (HMENU)0, localised, original, id);
  154. }
  155. inline const wchar_t *api_language::GetLanguageIdentifier(int mode)
  156. {
  157. return _call(API_LANGUAGE_GETLANGUAGEIDENTIFIER, (const wchar_t *)0, mode);
  158. }
  159. inline void *api_language::LoadResourceFromFileA(HINSTANCE hinst, HINSTANCE owner, LPCSTR lpType, LPCSTR lpName, DWORD* size)
  160. {
  161. return _call(API_LANGUAGE_LOADRESOURCEFROMFILEA, (void*)0, hinst, owner, lpType, lpName, size);
  162. }
  163. inline void *api_language::LoadResourceFromFileW(HINSTANCE hinst, HINSTANCE owner, LPCWSTR lpType, LPCWSTR lpName, DWORD* size)
  164. {
  165. return _call(API_LANGUAGE_LOADRESOURCEFROMFILEW, (void*)0, hinst, owner, lpType, lpName, size);
  166. }
  167. inline HACCEL api_language::LoadAcceleratorsA(HINSTANCE hinst, HINSTANCE owner, LPCSTR lpTableName)
  168. {
  169. return _call(API_LANGUAGE_LOADACCELERATORSA, (HACCEL)NULL, hinst, owner, lpTableName);
  170. }
  171. inline HACCEL api_language::LoadAcceleratorsW(HINSTANCE hinst, HINSTANCE owner, LPCWSTR lpTableName)
  172. {
  173. return _call(API_LANGUAGE_LOADACCELERATORSA, (HACCEL)NULL, hinst, owner, lpTableName);
  174. }
  175. inline BOOL api_language::UseUserNumericLocale()
  176. {
  177. return _call(API_LANGUAGE_USEUSERNUMERICLOCALE, (BOOL)0);
  178. }
  179. inline _locale_t api_language::Get_C_NumericLocale()
  180. {
  181. return _call(API_LANGUAGE_GET_C_NUMERICLOCALE, (_locale_t)0);
  182. }
  183. inline wchar_t *api_language::FormattedSizeString(wchar_t *out, int cchLen, __int64 size)
  184. {
  185. return _call(API_LANGUAGE_FORMATTEDSIZESTRING, (wchar_t*)0, out, cchLen, size);
  186. }
  187. // utility macros and relevant predefined variables for use with the service + macros
  188. extern api_language *languageManager;
  189. #define WASABI_API_LNG languageManager
  190. extern HINSTANCE api_localised_hinstance;
  191. #define WASABI_API_LNG_HINST api_localised_hinstance
  192. extern HINSTANCE api_orig_hinstance;
  193. #define WASABI_API_ORIG_HINST api_orig_hinstance
  194. #define WASABI_API_LNGSTR WASABI_API_LNG->GetString
  195. //#ifdef UNICODE
  196. //#define WASABI_API_LNGSTR WASABI_API_LNG->GetStringW
  197. //#else
  198. //#define WASABI_API_LNGSTR WASABI_API_LNG->GetStringA
  199. //#endif
  200. // use this is you want a temp copy of the string
  201. #define WASABI_API_LNGSTRING(uID) \
  202. WASABI_API_LNGSTR(WASABI_API_LNG_HINST,WASABI_API_ORIG_HINST,uID)
  203. // use this is you want a temp copy of the string but need it to fallback to a different module
  204. #define WASABI_API_LNGSTRING_HINST(hinst,uID) \
  205. WASABI_API_LNGSTR(WASABI_API_LNG_HINST,hinst,uID)
  206. // use this is you want a copy of the string
  207. #define WASABI_API_LNGSTRING_BUF(uID,buf,len) \
  208. WASABI_API_LNGSTR(WASABI_API_LNG_HINST,WASABI_API_ORIG_HINST,uID,buf,len)
  209. // use this is you want a copy of the string but need it to fallback to a different module
  210. #define WASABI_API_LNGSTRING_HINST_BUF(hinst,uID,buf,len) \
  211. WASABI_API_LNGSTR(WASABI_API_LNG_HINST,hinst,uID,buf,len)
  212. // unicode versions of the above macros
  213. #define WASABI_API_LNGSTRW WASABI_API_LNG->GetStringW
  214. #define WASABI_API_LNGSTRINGW(uID) \
  215. WASABI_API_LNGSTRW(WASABI_API_LNG_HINST,WASABI_API_ORIG_HINST,uID)
  216. #define WASABI_API_LNGSTRINGW_HINST(hinst,uID) \
  217. WASABI_API_LNGSTRW(WASABI_API_LNG_HINST,hinst,uID)
  218. #define WASABI_API_LNGSTRINGW_BUF(uID,buf,len) \
  219. WASABI_API_LNGSTRW(WASABI_API_LNG_HINST,WASABI_API_ORIG_HINST,uID,buf,len)
  220. #define WASABI_API_LNGSTRINGW_BUF_HINST(hinst,uID,buf,len) \
  221. WASABI_API_LNGSTRW(WASABI_API_LNG_HINST,hinst,uID,buf,len)
  222. // Dialog handling functions (will revert back to the non-localised version if not valid/present)
  223. #define WASABI_API_CREATEDIALOGPARAM(id, parent, proc, param) \
  224. WASABI_API_LNG->CreateLDialogParam(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, id, parent, (DLGPROC)proc, param)
  225. #define WASABI_API_CREATEDIALOG(id, parent, proc) \
  226. WASABI_API_LNG->CreateLDialogParam(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, id, parent, (DLGPROC)proc, 0)
  227. #define WASABI_API_CREATEDIALOGPARAMW(id, parent, proc, param) \
  228. WASABI_API_LNG->CreateLDialogParamW(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, id, parent, (DLGPROC)proc, param)
  229. #define WASABI_API_CREATEDIALOGW(id, parent, proc) \
  230. WASABI_API_LNG->CreateLDialogParamW(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, id, parent, (DLGPROC)proc, 0)
  231. #define WASABI_API_DIALOGBOXPARAM(id, parent, proc, param) \
  232. WASABI_API_LNG->LDialogBoxParam(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, id, parent, (DLGPROC)proc, param)
  233. #define WASABI_API_DIALOGBOX(id, parent, proc) \
  234. WASABI_API_LNG->LDialogBoxParam(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, id, parent, (DLGPROC)proc, 0)
  235. #define WASABI_API_DIALOGBOXPARAMW(id, parent, proc, param) \
  236. WASABI_API_LNG->LDialogBoxParamW(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, id, parent, (DLGPROC)proc, param)
  237. #define WASABI_API_DIALOGBOXW(id, parent, proc) \
  238. WASABI_API_LNG->LDialogBoxParamW(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, id, parent, (DLGPROC)proc, 0)
  239. #define WASABI_API_LOADMENU(id) \
  240. WASABI_API_LNG->LoadLMenu(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, id)
  241. #define WASABI_API_LOADMENUW(id) \
  242. WASABI_API_LNG->LoadLMenuW(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, id)
  243. #define WASABI_API_LOADACCELERATORSA(__id) \
  244. WASABI_API_LNG->LoadAcceleratorsA(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, MAKEINTRESOURCEA(__id))
  245. #define WASABI_API_LOADACCELERATORSW(__id) \
  246. WASABI_API_LNG->LoadAcceleratorsW(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, MAKEINTRESOURCEW(__id))
  247. #ifdef UNICODE
  248. #define WASABI_API_LOADACCELERATORS WASABI_API_LOADACCELERATORSW
  249. #else
  250. #define WASABI_API_LOADACCELERATORS WASABI_API_LOADACCELERATORSA
  251. #endif
  252. #define WASABI_API_START_LANG(orig_hinst, guid) \
  253. { \
  254. WASABI_API_ORIG_HINST = orig_hinst; \
  255. WASABI_API_LNG_HINST = WASABI_API_LNG->StartLanguageSupport(WASABI_API_ORIG_HINST,guid); \
  256. }
  257. #define WASABI_API_LOADRESFROMFILEA(lpType, lpName, size) \
  258. WASABI_API_LNG->LoadResourceFromFileA(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, lpType, lpName, size)
  259. #define WASABI_API_LOADRESFROMFILEW(lpType, lpName, size) \
  260. WASABI_API_LNG->LoadResourceFromFileW(WASABI_API_LNG_HINST, WASABI_API_ORIG_HINST, lpType, lpName, size)
  261. // {30AED4E5-EF10-4277-8D49-27AB5570E891}
  262. static const GUID languageApiGUID =
  263. { 0x30aed4e5, 0xef10, 0x4277, { 0x8d, 0x49, 0x27, 0xab, 0x55, 0x70, 0xe8, 0x91 } };
  264. #endif