1
0

options_lang.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. /** (c) Nullsoft, Inc. C O N F I D E N T I A L
  2. ** Filename:
  3. ** Project:
  4. ** Description:
  5. ** Author:
  6. ** Created:
  7. **/
  8. #include "main.h"
  9. #include "language.h"
  10. #include "resource.h"
  11. #include "Options.h"
  12. #include "main.hpp"
  13. static WNDPROC list_oldWndProc;
  14. static wchar_t rename_lang[MAX_PATH];
  15. static int cur_lang = LB_ERR;
  16. static BOOL FillEnumRec(ENUMLANG *pel, LPCWSTR pszFileName, BOOL bDirectory, LPWSTR pszName, INT cchName, LPCWSTR pszActiveFile)
  17. {
  18. //if (bDirectory) return FALSE;
  19. LPCWSTR pExt = 0;
  20. if (!bDirectory)
  21. {
  22. pExt = PathFindExtensionW(pszFileName);
  23. if (L'.' != *pExt) return FALSE;
  24. pExt++;
  25. }
  26. DWORD lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
  27. if (CSTR_EQUAL == CompareStringW(lcid, NORM_IGNORECASE, pExt, -1, L"wlz", -1)) pel->nType = LANG_FILETYPE_WLZ;
  28. else if (CSTR_EQUAL == CompareStringW(lcid, NORM_IGNORECASE, pExt, -1, L"zip", -1)) pel->nType = LANG_FILETYPE_ZIP;
  29. else
  30. {
  31. wchar_t check[MAX_PATH] = {0};
  32. PathCombineW(check, LANGDIR, pszFileName);
  33. PathCombineW(check, check, L"winamp.lng");
  34. if (!PathFileExistsW(check)) return FALSE;
  35. pel->nType = LANG_FILETYPE_DIR;
  36. }
  37. if (!bDirectory)
  38. {
  39. LPCWSTR pszFile = PathFindFileNameW(pszFileName);
  40. StringCchCopyNW(pszName, cchName, pszFile, (size_t)(pExt - pszFile - 1));
  41. }
  42. else
  43. StringCchCopyW(pszName, cchName, pszFileName);
  44. pel->pszFileName = pszFileName;
  45. pel->pszName = pszName;
  46. pel->bActive = (pszActiveFile && CSTR_EQUAL == CompareStringW(lcid, NORM_IGNORECASE, pszActiveFile, -1, pel->pszFileName, -1));
  47. return TRUE;
  48. }
  49. int EnumerateLanguages(ENUMLANGPROC fnEnumLang, void *user)
  50. {
  51. if (!fnEnumLang) return FALSE;
  52. WIN32_FIND_DATAW d = {0};
  53. wchar_t dirmask[1024] = {0}, szName[MAX_PATH] = {0}, *pszActive = 0;
  54. ENUMLANG el = {0};
  55. BOOL bActiveFound = FALSE, bTerminated = FALSE;
  56. if (*config_langpack)
  57. {
  58. pszActive = PathFindFileNameW(config_langpack);
  59. if (pszActive != config_langpack && BuildFullPath(LANGDIR, config_langpack, szName, sizeof(szName)/sizeof(wchar_t)))
  60. {
  61. INT cr = ComparePath(szName, pszActive, LANGDIR);
  62. if(cr && CSTR_EQUAL != cr && PathFileExistsW(szName))
  63. {
  64. if (FillEnumRec(&el, config_langpack, FALSE, szName, sizeof(szName)/sizeof(wchar_t), NULL))
  65. {
  66. el.bActive = TRUE;
  67. bActiveFound = TRUE;
  68. if (!fnEnumLang(&el, user)) return FALSE;
  69. }
  70. }
  71. }
  72. }
  73. else pszActive = NULL;
  74. PathCombineW(dirmask, LANGDIR, L"*");
  75. HANDLE h = FindFirstFileW(dirmask, &d);
  76. if (h != INVALID_HANDLE_VALUE)
  77. {
  78. do
  79. {
  80. if (!wcscmp(d.cFileName, L".") || !wcscmp(d.cFileName, L"..")) continue;
  81. if (FillEnumRec(&el, d.cFileName, (FILE_ATTRIBUTE_DIRECTORY & d.dwFileAttributes), szName, sizeof(szName)/sizeof(wchar_t), (bActiveFound) ? NULL : pszActive))
  82. {
  83. if (el.bActive) bActiveFound = TRUE;
  84. if (!fnEnumLang(&el, user))
  85. {
  86. bTerminated = TRUE;
  87. break;
  88. }
  89. }
  90. }
  91. while (FindNextFileW(h, &d));
  92. FindClose(h);
  93. }
  94. if (!bTerminated)
  95. {
  96. el.pszFileName = NULL;
  97. el.pszName = L"English (US)";
  98. el.nType = LANG_FILETYPE_EMBED;
  99. el.bActive = !bActiveFound;
  100. bTerminated = !fnEnumLang(&el, user);
  101. }
  102. return !bTerminated;
  103. }
  104. static int CALLBACK BrowseLangCallbackProc( HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
  105. {
  106. switch (uMsg)
  107. {
  108. case BFFM_INITIALIZED:
  109. {
  110. SetWindowTextW(hwnd, getStringW(IDS_P_SELECT_LANGDIR,NULL,0));
  111. SendMessageW(hwnd, BFFM_SETSELECTIONW, 1, (LPARAM)LANGDIR);
  112. }
  113. return 0;
  114. }
  115. return 0;
  116. }
  117. static void _setreadme(HWND hwndDlg, wchar_t* readme_only_wlz_extraction)
  118. {
  119. if (config_langpack[0] || readme_only_wlz_extraction && readme_only_wlz_extraction[0])
  120. {
  121. wchar_t s[MAX_PATH] = {0}, *dirpath = (readme_only_wlz_extraction?readme_only_wlz_extraction:lang_directory);
  122. FILE *fp = NULL;
  123. PathCombineW(s, dirpath, L"readme.txt");
  124. fp=_wfopen(s,L"rt");
  125. if (!fp)
  126. {
  127. PathCombineW(s, dirpath, L"read me.txt");
  128. fp=_wfopen(s,L"rt");
  129. }
  130. if (!fp)
  131. {
  132. WIN32_FIND_DATAW d = {0};
  133. PathCombineW(s, dirpath, L"*.txt");
  134. HANDLE h = FindFirstFileW(s,&d);
  135. s[0]=0;
  136. if (h != INVALID_HANDLE_VALUE)
  137. {
  138. do
  139. {
  140. if (NULL != PathCombineW(s, dirpath, d.cFileName))
  141. break;
  142. } while (FindNextFileW(h,&d));
  143. FindClose(h);
  144. fp=_wfopen(s,L"rt");
  145. }
  146. }
  147. if (fp)
  148. {
  149. SetDialogBoxFromFile(fp, hwndDlg, IDC_EDIT1);
  150. fclose(fp);
  151. }
  152. else
  153. SetDlgItemTextW(hwndDlg,IDC_EDIT1,getStringW(IDS_P_SKIN_NO_INFO_FOUND,NULL,0));
  154. }
  155. else SetDlgItemTextA(hwndDlg,IDC_EDIT1,"\tWinamp Default Language");
  156. }
  157. static BOOL CALLBACK renameSkinProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  158. {
  159. switch (uMsg)
  160. {
  161. case WM_INITDIALOG:
  162. SetDlgItemTextW(hwndDlg,IDC_OLD,rename_lang);
  163. SetDlgItemTextW(hwndDlg,IDC_NEW,rename_lang);
  164. SetWindowTextW(hwndDlg,getStringW(IDS_RENAME_WLZ, NULL, 0));
  165. return TRUE;
  166. case WM_COMMAND:
  167. switch (LOWORD(wParam))
  168. {
  169. case IDOK:
  170. GetDlgItemTextW(hwndDlg,IDC_NEW,rename_lang,sizeof(rename_lang)/sizeof(*rename_lang));
  171. EndDialog(hwndDlg,!!rename_lang[0]);
  172. return 0;
  173. case IDCANCEL:
  174. EndDialog(hwndDlg,0);
  175. return 0;
  176. }
  177. return 0;
  178. }
  179. return 0;
  180. }
  181. static DWORD WINAPI list_newWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  182. {
  183. if(uMsg == WM_RBUTTONUP)
  184. {
  185. PostMessageW(GetParent(hwndDlg),WM_USER+0x123,0,0);
  186. }
  187. return CallWindowProcW(list_oldWndProc,hwndDlg,uMsg,wParam,lParam);
  188. }
  189. static void LangSwitchDelayText(HWND hwndDlg){
  190. if(config_langpack2[0]){
  191. wchar_t tmp[MAX_PATH] = {0};
  192. StringCchPrintfW(tmp,MAX_PATH,getStringW(IDS_WA_RESTART_FOR_WLZ_NEEDED,NULL,0),
  193. (config_langpack2[0]=='<')?L"Winamp Default Language":config_langpack2);
  194. SetDlgItemTextW(hwndDlg,IDC_LANG_RESTART_TEXT,tmp);
  195. }
  196. ShowWindow(GetDlgItem(hwndDlg,IDC_LANG_RESTART_TEXT),config_langpack2[0]?SW_SHOW:SW_HIDE);
  197. }
  198. void LangSwitchToLangPrompt(HWND hwndDlg, wchar_t* newLang)
  199. {
  200. wchar_t title[64] = {0};
  201. // will do an instant switch to the selected language pack
  202. if (!(GetAsyncKeyState(VK_SHIFT)&0x8000) && MessageBoxW(hwndDlg,getStringW(IDS_LANGCHANGE,NULL,0),
  203. getStringW(IDS_LANGCHANGE_TITLE,title,64),MB_ICONEXCLAMATION|MB_OKCANCEL) == IDOK ||
  204. (GetAsyncKeyState(VK_SHIFT)&0x8000))
  205. {
  206. config_langpack2[0] = 0;
  207. lstrcpynW(config_langpack,newLang,MAX_PATH);
  208. config_save_langpack_var();
  209. _w_i("show_prefs", 25);
  210. PostMessageW(hMainWindow,WM_USER,0,IPC_RESTARTWINAMP);
  211. }
  212. // will switch to the selected language pack on the next restart (as per the options description)
  213. // need to indicate which one is pending to be chosen (if there is one) on the dialog
  214. // otherwise it might cause confusion with showing one selected when it otherwise shouldn't be
  215. else
  216. {
  217. // fool the exit code to think that we've got a change to save out
  218. if(!newLang[0]) newLang[0] = '<';
  219. lstrcpynW(config_langpack2,newLang,MAX_PATH);
  220. }
  221. }
  222. static void LangSwitchToLang(HWND hwndDlg, int id)
  223. {
  224. wchar_t buf2[1024] = {0}, buf[1024] = {0}, *o = buf, *p = config_langpack;
  225. int ld = (id!=-1?id:SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_GETCURSEL,0,0));
  226. if (ld == LB_ERR) return;
  227. int itemdata = SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_GETITEMDATA,ld,0);
  228. SendDlgItemMessageW(hwndDlg,IDC_SELBOX,LB_GETTEXT,ld,(LPARAM)buf2);
  229. if (config_langpack[0])
  230. {
  231. if (_wcsicmp(p, L"winamp.exe"))
  232. {
  233. while (p && *p != L'.' && *p && o-buf < 512)
  234. {
  235. wchar_t *t=CharNextW(p);
  236. memcpy(o,p,t-p);
  237. o+=t-p;
  238. p=t;
  239. }
  240. *o=0;
  241. }
  242. }
  243. if (!_wcsicmp(buf,buf2)) return; // no change
  244. if (buf2[0])
  245. {
  246. if (itemdata == 2)
  247. {
  248. StringCbCatW(buf2, sizeof(buf2), L".wlz");
  249. }
  250. else if (itemdata == 4)
  251. {
  252. StringCbCatW(buf2, sizeof(buf2), L".zip");
  253. }
  254. }
  255. LangSwitchToLangPrompt(hwndDlg, buf2);
  256. LangSwitchDelayText(hwndDlg);
  257. }
  258. static void LangRenameLang(HWND hwndDlg, int id)
  259. {
  260. int x = (id!=-1?id:SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_GETCURSEL,0,0));
  261. int extidx = SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_GETITEMDATA,x,0);
  262. int is_cur_lp = 0;
  263. wchar_t test_lng[MAX_PATH] = {0};
  264. SendDlgItemMessageW(hwndDlg,IDC_SELBOX,LB_GETTEXT,x,(LPARAM)rename_lang);
  265. SendDlgItemMessageW(hwndDlg,IDC_SELBOX,LB_GETTEXT,x,(LPARAM)test_lng);
  266. switch (extidx)
  267. {
  268. case 2:
  269. {
  270. StringCchCatW(test_lng, MAX_PATH, L".wlz");
  271. break;
  272. }
  273. case 4:
  274. {
  275. StringCchCatW(test_lng, MAX_PATH, L".zip");
  276. break;
  277. }
  278. default: break;
  279. }
  280. // make sure if renaming the current lang pack that it's followed back through
  281. if (!_wcsicmp(test_lng,config_langpack))
  282. {
  283. is_cur_lp = 1;
  284. }
  285. if (rename_lang[0] && _wcsicmp(rename_lang, L"English (US)"))
  286. {
  287. wchar_t oldlang[MAX_PATH] = {0};
  288. lstrcpynW(oldlang, rename_lang, MAX_PATH);
  289. if (LPDialogBoxW(IDD_RENAMESKIN,hwndDlg,renameSkinProc) && wcscmp(oldlang,rename_lang))
  290. {
  291. wchar_t oldname[MAX_PATH] = {0}, newname[MAX_PATH] = {0};
  292. PathCombineW(oldname, LANGDIR, oldlang);
  293. PathCombineW(newname, LANGDIR, rename_lang);
  294. switch (extidx)
  295. {
  296. case 2: StringCchCatW(oldname,MAX_PATH, L".wlz"); StringCchCatW(newname,MAX_PATH,L".wlz"); break;
  297. case 4: StringCchCatW(oldname,MAX_PATH, L".zip"); StringCchCatW(newname,MAX_PATH,L".zip"); break;
  298. default: break;
  299. }
  300. if (MoveFileW(oldname,newname))
  301. {
  302. SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_DELETESTRING,x,0);
  303. SendDlgItemMessageW(hwndDlg,IDC_SELBOX,LB_INSERTSTRING,x,(LPARAM)rename_lang);
  304. int par=0;
  305. SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_SETITEMDATA,x,par);
  306. SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_SETCURSEL,x,0);
  307. // only resave if the rename worked
  308. if(is_cur_lp)
  309. {
  310. wchar_t *p = scanstr_backW(newname,L"\\",0)+1;
  311. lstrcpynW(config_langpack, p, MAX_PATH);
  312. config_save_langpack_var();
  313. }
  314. }
  315. else
  316. {
  317. wchar_t title[64] = {0};
  318. MessageBoxW(hwndDlg,getStringW(IDS_P_LANG_ERR_RENAME,NULL,0),
  319. getStringW(IDS_P_LANG_ERR_RENAME_TITLE,title,64),MB_OK);
  320. }
  321. }
  322. }
  323. }
  324. static void LangDeleteLang(HWND hwndDlg, int id)
  325. {
  326. wchar_t lang[MAX_PATH] = {0};
  327. int cur = SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_GETCURSEL,0,0);
  328. int x = (id != -1 ? id : cur);
  329. if (x == LB_ERR) return;
  330. SendDlgItemMessageW(hwndDlg,IDC_SELBOX,LB_GETTEXT,x,(LPARAM)lang);
  331. switch (SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_GETITEMDATA,x,0))
  332. {
  333. case 2:
  334. {
  335. StringCchCatW(lang, MAX_PATH, L".wlz");
  336. break;
  337. }
  338. case 4:
  339. {
  340. StringCchCatW(lang, MAX_PATH, L".zip");
  341. break;
  342. }
  343. default: break;
  344. }
  345. if (lang[0] && _wcsicmp(lang, L"English (US)"))
  346. {
  347. wchar_t buf[2048] = {0};
  348. StringCchPrintfW(buf, 2048, getStringW(IDS_P_LANG_PACK_DELETEWLZ_PROMPT,NULL,0),lang);
  349. if (MessageBoxW(hwndDlg,buf,getStringW(IDS_P_LANG_PACK_DELETEWLZ,NULL,0),MB_YESNO|MB_ICONQUESTION) == IDYES)
  350. {
  351. PathCombineW(buf, LANGDIR, lang);
  352. IFileTypeRegistrar *registrar=0;
  353. if (GetRegistrar(&registrar, true) == 0 && registrar)
  354. {
  355. registrar->DeleteItem(buf);
  356. registrar->Release();
  357. }
  358. if(id == cur_lang)
  359. SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_SETCURSEL,0,0);
  360. SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_DELETESTRING,x,0);
  361. if(id == cur_lang)
  362. {
  363. cur_lang = 0;
  364. config_langpack[0]=0;
  365. config_save_langpack_var();
  366. wchar_t title[64] = {0};
  367. if (MessageBoxW(hwndDlg,getStringW(IDS_LANGCHANGE,NULL,0),
  368. getStringW(IDS_LANGCHANGE_TITLE,title,64),MB_ICONEXCLAMATION|MB_OKCANCEL) == IDOK)
  369. _w_i("show_prefs", 25);
  370. PostMessageW(hMainWindow,WM_USER,0,IPC_RESTARTWINAMP);
  371. }
  372. }
  373. }
  374. }
  375. static BOOL CALLBACK AddLangToListBox(ENUMLANG *pel, void *user)
  376. {
  377. int index = SendMessageW((HWND)user, LB_ADDSTRING, 0, (LPARAM)pel->pszName);
  378. if (LB_ERR != index)
  379. {
  380. SendMessageW((HWND)user, LB_SETITEMDATA, index, (LPARAM)pel->nType);
  381. if (pel->bActive) SendMessageW((HWND)user, LB_SETCURSEL, index, 0);
  382. }
  383. return TRUE;
  384. }
  385. INT_PTR CALLBACK LangProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  386. {
  387. hi helpinfo[]={{IDC_SELBOX,IDS_P_SETUP_LANG},
  388. {IDC_CHDIR,IDS_P_LNG_CHDR}};
  389. DO_HELP();
  390. switch (uMsg)
  391. {
  392. case WM_INITDIALOG:
  393. link_startsubclass(hwndDlg, IDC_WINAMPLINK);
  394. case WM_USER+50:
  395. {
  396. HWND hw = GetDlgItem(hwndDlg,IDC_SELBOX);
  397. SetDlgItemTextW(hwndDlg,IDC_LANG_ID_STR,langManager->GetLanguageIdentifier(LANG_IDENT_STR));
  398. if(uMsg == WM_INITDIALOG)
  399. {
  400. int tabs[] = {150};
  401. SendMessageW(hw,LB_SETTABSTOPS,1,(LPARAM)tabs);
  402. SetDlgItemTextW(hwndDlg, IDC_CHDIR, LANGDIR);
  403. list_oldWndProc=(WNDPROC)SetWindowLongPtrW(hw,GWLP_WNDPROC,(LONG_PTR)list_newWndProc);
  404. DirectMouseWheel_EnableConvertToMouseWheel(hw, TRUE);
  405. CheckDlgButton(hwndDlg, IDC_SHOW_LNG_PACK, config_wlz_menu);
  406. CheckDlgButton(hwndDlg, IDC_LANG_INSTALL_PROMPT, config_wlz_prompt);
  407. }
  408. wchar_t selected[MAX_PATH] = {0};
  409. SendMessageW(hw,WM_SETREDRAW,FALSE,0);
  410. EnumerateLanguages(AddLangToListBox, hw);
  411. int index = (INT)SendMessageW(hw,LB_GETCURSEL,0,0);
  412. if (LB_ERR == index || LB_ERR == SendMessageW(hw, LB_GETTEXT, index, (LPARAM)selected))
  413. selected[0] = 0x00;
  414. index = (INT)SendMessageW(hw, LB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)L"English (US)");
  415. if (LB_ERR != index)
  416. {
  417. SendMessageW(hw, LB_DELETESTRING, index, 0);
  418. SendMessageW(hw, LB_INSERTSTRING, 0, (LPARAM)L"English (US)");
  419. }
  420. index = (*selected) ? (INT)SendMessageW(hw, LB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)selected) : LB_ERR;
  421. if (LB_ERR == index) index = 0;
  422. SendMessageW(hw,LB_SETCURSEL, index, 0);
  423. cur_lang = index;
  424. // set buttons to the correct state on init
  425. SendMessageW(hwndDlg,WM_COMMAND,MAKEWPARAM(IDC_SELBOX,LBN_SELCHANGE),
  426. (LPARAM)GetDlgItem(hwndDlg,IDC_SELBOX));
  427. SendMessageW(hw,WM_SETREDRAW,TRUE,0);
  428. _setreadme(hwndDlg,0);
  429. LangSwitchDelayText(hwndDlg);
  430. }
  431. return FALSE;
  432. case WM_DESTROY:
  433. {
  434. HWND listWindow;
  435. listWindow = GetDlgItem(hwndDlg, IDC_SELBOX);
  436. if (NULL != listWindow)
  437. DirectMouseWheel_EnableConvertToMouseWheel(listWindow, FALSE);
  438. }
  439. return FALSE;
  440. case WM_USER+0x123:
  441. {
  442. HMENU h = GetSubMenu(GetSubMenu(top_menu,5), 1);
  443. if (h)
  444. {
  445. POINT p,ps;
  446. GetCursorPos(&p);
  447. ps=p;
  448. ScreenToClient(GetDlgItem(hwndDlg,IDC_SELBOX),&ps);
  449. LRESULT x = SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_ITEMFROMPOINT,0,MAKELPARAM(ps.x,ps.y));
  450. if (HIWORD(x)==0 && (x=LOWORD(x)) >= 0)
  451. {
  452. wchar_t lang[MAX_PATH] = {0};
  453. SendDlgItemMessageW(hwndDlg,IDC_SELBOX,LB_GETTEXT,x,(LPARAM)lang);
  454. EnableMenuItem(h,0,MF_BYPOSITION|((LOWORD(x)!=cur_lang)?MF_ENABLED:MF_GRAYED));
  455. EnableMenuItem(h,2,MF_BYPOSITION|(x ? MF_ENABLED : MF_GRAYED));
  456. EnableMenuItem(h,3,MF_BYPOSITION|(x ? MF_ENABLED : MF_GRAYED));
  457. //int sel=DoTrackPopup(h,TPM_RETURNCMD|TPM_NONOTIFY|TPM_RIGHTBUTTON,p.x,p.y,hwndDlg);
  458. int sel=TrackPopupMenu(h,TPM_RETURNCMD|TPM_NONOTIFY|TPM_RIGHTBUTTON,p.x,p.y,0,hwndDlg,NULL);
  459. if (sel)
  460. {
  461. if (sel == ID_LANG_SWITCHTOLANGUAGEPACK)
  462. {
  463. LangSwitchToLang(hwndDlg,LOWORD(x));
  464. }
  465. else if (sel == ID_LANG_RENAMELANGUAGEPACK)
  466. {
  467. LangRenameLang(hwndDlg,LOWORD(x));
  468. }
  469. else if (sel == ID_LANG_DELETELANGUAGEPACK)
  470. {
  471. LangDeleteLang(hwndDlg,LOWORD(x));
  472. }
  473. }
  474. }
  475. }
  476. return 0;
  477. }
  478. case WM_COMMAND:
  479. {
  480. switch (LOWORD(wParam))
  481. {
  482. case IDC_SELECT_LNG_PACK:
  483. {
  484. SendMessageW(hwndDlg,WM_COMMAND,MAKEWPARAM(IDC_SELBOX,LBN_DBLCLK),
  485. (LPARAM)GetDlgItem(hwndDlg,IDC_SELBOX));
  486. break;
  487. }
  488. case IDC_RENAME_LNG_PACK:
  489. {
  490. LangRenameLang(hwndDlg,-1);
  491. return 0;
  492. }
  493. case IDC_DELETE_LNG_PACK:
  494. {
  495. LangDeleteLang(hwndDlg,-1);
  496. return 0;
  497. }
  498. case IDC_LANG_INSTALL_PROMPT:
  499. {
  500. config_wlz_prompt = !config_wlz_prompt;
  501. return 0;
  502. }
  503. case IDC_SHOW_LNG_PACK:
  504. {
  505. config_wlz_menu = !config_wlz_menu;
  506. if (config_wlz_menu)
  507. {
  508. MENUITEMINFOW mii = {sizeof(mii), MIIM_SUBMENU | MIIM_TYPE | MIIM_ID, MFT_STRING, };
  509. mii.hSubMenu = g_submenus_lang = CreatePopupMenu();
  510. mii.dwTypeData = getStringW(IDS_LANGUAGEPACKS_MENU, NULL, 0);
  511. mii.cch = (UINT)wcslen(mii.dwTypeData);
  512. g_submenus_lang_id = mii.wID = unique_loword_command++;
  513. InsertMenuItemW(main_menu, MAINMENU_OPTIONS_BASE+4, TRUE, &mii);
  514. mii.hSubMenu = g_submenus_lang;
  515. mii.dwTypeData = getStringW(IDS_LANGUAGEPACKS_MENU, NULL, 0);
  516. mii.cch = (UINT)wcslen(mii.dwTypeData);
  517. mii.wID = g_submenus_lang_id;
  518. InsertMenuItemW(GetSubMenu(v5_top_menu, 2), 1, TRUE, &mii);
  519. g_mm_ffoptionsbase_adj++;
  520. }
  521. else
  522. {
  523. DeleteMenu(main_menu, g_submenus_lang_id, MF_BYCOMMAND);
  524. DeleteMenu(GetSubMenu(v5_top_menu, 2), g_submenus_lang_id, MF_BYCOMMAND);
  525. g_mm_ffoptionsbase_adj--;
  526. g_submenus_lang_id = 0;
  527. g_submenus_lang = 0;
  528. }
  529. break;
  530. }
  531. case IDC_WINAMPLINK:
  532. {
  533. myOpenURLWithFallback(hwndDlg, L"http://www.google.com/search?q=%22winamp+language+packs%22+5.9", L"http://forums.winamp.com/showthread.php?t=458120#lang");
  534. return 0;
  535. }
  536. case IDC_CHDIR:
  537. {
  538. BROWSEINFOW bi = {0};
  539. bi.hwndOwner = hwndDlg;
  540. bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
  541. bi.lpfn = BrowseLangCallbackProc;
  542. ITEMIDLIST *idlist = SHBrowseForFolderW(&bi);
  543. if (idlist)
  544. {
  545. wchar_t path[MAX_PATH] = {0};
  546. SHGetPathFromIDListW(idlist, path);
  547. Shell_Free(idlist);
  548. if(!PathIsRootW(path))
  549. {
  550. wchar_t orig[MAX_PATH] = {0};
  551. StringCchCopyW(orig, MAX_PATH, LANGDIR);
  552. StringCchCopyW(LANGDIR, MAX_PATH, path);
  553. _w_sW("LangDir", LANGDIR);
  554. wchar_t message[2048] = {0};
  555. StringCchPrintfW(message,2048,getStringW(IDS_LANG_DIR_MOVE_MESSAGE,NULL,0),orig,LANGDIR);
  556. if(MessageBoxW(hwndDlg, message, getStringW(IDS_LANG_DIR_MOVE,NULL,0),MB_YESNO|MB_ICONQUESTION)==IDYES)
  557. {
  558. IFileTypeRegistrar *registrar=0;
  559. if (GetRegistrar(&registrar, true) == 0 && registrar)
  560. {
  561. registrar->MoveDirectoryContents(orig,LANGDIR);
  562. registrar->Release();
  563. }
  564. }
  565. SendMessageW(GetDlgItem(hwndDlg,IDC_SELBOX),LB_RESETCONTENT,0,0);
  566. SetDlgItemTextW(hwndDlg, IDC_CHDIR, LANGDIR);
  567. SendMessageW(hwndDlg,WM_USER+50,0,0);
  568. }
  569. else
  570. {
  571. wchar_t message[512] = {0};
  572. MessageBoxW(hwndDlg, getStringW(IDS_DIR_MOVE_ERROR, message, 512),
  573. getStringW(IDS_LANG_DIR_MOVE,NULL,0), MB_OK|MB_ICONEXCLAMATION);
  574. }
  575. }
  576. return FALSE;
  577. }
  578. case IDC_SELBOX:
  579. {
  580. if (HIWORD(wParam) == LBN_DBLCLK)
  581. {
  582. LangSwitchToLang(hwndDlg,-1);
  583. }
  584. if (HIWORD(wParam) == LBN_SELCHANGE)
  585. {
  586. int cur = SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_GETCURSEL,0,0);
  587. int en = SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_GETITEMDATA,cur,0);
  588. EnableWindow(GetDlgItem(hwndDlg,IDC_RENAME_LNG_PACK),cur);
  589. EnableWindow(GetDlgItem(hwndDlg,IDC_DELETE_LNG_PACK),cur);
  590. EnableWindow(GetDlgItem(hwndDlg,IDC_SELECT_LNG_PACK),cur!=cur_lang);
  591. wchar_t test_lng[MAX_PATH] = {0};
  592. SendDlgItemMessageW(hwndDlg,IDC_SELBOX,LB_GETTEXT,cur,(LPARAM)test_lng);
  593. if (en == 2) StringCchCatW(test_lng, MAX_PATH, L".wlz");
  594. else if (en == 4) StringCchCatW(test_lng, MAX_PATH, L".zip");
  595. PathCombineW(test_lng, LANGDIR, test_lng);
  596. SetDlgItemTextW(hwndDlg,IDC_LANG_INFO_STR,
  597. getStringW((cur!=cur_lang)?IDS_SEL_WLZ_INFO:IDS_CUR_WLZ_INFO,NULL,0));
  598. SetDlgItemTextW(hwndDlg,IDC_LANG_ID_STR,(cur!=cur_lang)?L"":langManager->GetLanguageIdentifier(LANG_IDENT_STR));
  599. // try to pull information about the selected wlz from the current selection
  600. if(cur){
  601. if(en && cur!=cur_lang){
  602. extract_wlz_to_dir(test_lng, 0);
  603. _setreadme(hwndDlg,(cur!=cur_lang)?test_lng:0);
  604. _cleanupDirW(test_lng);
  605. }
  606. else
  607. _setreadme(hwndDlg,(!en ? test_lng : 0));
  608. }
  609. else{
  610. SetDlgItemTextA(hwndDlg,IDC_EDIT1,"\tWinamp Default Language");
  611. }
  612. }
  613. return FALSE;
  614. }
  615. }
  616. return FALSE;
  617. }
  618. }
  619. link_handledraw(hwndDlg,uMsg,wParam,lParam);
  620. const int controls[] =
  621. {
  622. IDC_EDIT1,
  623. };
  624. if (FALSE != DirectMouseWheel_ProcessDialogMessage(hwndDlg, uMsg, wParam, lParam, controls, ARRAYSIZE(controls)))
  625. {
  626. return TRUE;
  627. }
  628. return 0;
  629. }