options_skin.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  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 "../nu/AutoWide.h"
  11. #include "resource.h"
  12. #include "Options.h"
  13. #include "main.hpp"
  14. #include "language.h"
  15. static WNDPROC list_oldWndProc;
  16. static wchar_t rename_skin[MAX_PATH];
  17. static wchar_t CLASSIC_NAME[64];
  18. static BOOL FillEnumRec(ENUMSKIN *pes, LPCWSTR pszFileName, BOOL bDirectory, LPWSTR pszName, INT cchName, LPCWSTR pszActiveFile)
  19. {
  20. LPCWSTR pExt, pszFile;
  21. DWORD lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
  22. if (bDirectory)
  23. {
  24. if (pszFileName[0] == L'.' && ((pszFileName[1] == L'.' && pszFileName[2] == 0x00) || pszFileName[1] == 0x00)) return FALSE;
  25. pes->nType = SKIN_FILETYPE_DIR;
  26. pExt = pszFileName + lstrlenW(pszFileName) + 1;
  27. }
  28. else
  29. {
  30. pExt = PathFindExtensionW(pszFileName);
  31. if (L'.' != *pExt) return FALSE;
  32. pExt++;
  33. if (CSTR_EQUAL == CompareStringW(lcid, NORM_IGNORECASE, pExt, -1, L"zip", -1)) pes->nType = SKIN_FILETYPE_ZIP;
  34. else if (CSTR_EQUAL == CompareStringW(lcid, NORM_IGNORECASE, pExt, -1, L"wal", -1)) pes->nType = SKIN_FILETYPE_WAL;
  35. else if (CSTR_EQUAL == CompareStringW(lcid, NORM_IGNORECASE, pExt, -1, L"wsz", -1)) pes->nType = SKIN_FILETYPE_WSZ;
  36. else return FALSE;
  37. }
  38. pszFile = PathFindFileNameW(pszFileName);
  39. StringCchCopyNW(pszName, cchName, pszFile, (size_t)(pExt - pszFile - 1));
  40. pes->pszFileName = pszFileName;
  41. pes->pszName = pszName;
  42. pes->bActive = (pszActiveFile && CSTR_EQUAL == CompareStringW(lcid, NORM_IGNORECASE, pszActiveFile, -1, pes->pszFileName, -1));
  43. return TRUE;
  44. }
  45. int EnumerateSkins(ENUMSKINPROC fnEnumSkin, void *user)
  46. {
  47. if (!fnEnumSkin) return FALSE;
  48. HANDLE h;
  49. BOOL bActiveFound, bTerminated;
  50. WIN32_FIND_DATAW d;
  51. wchar_t dirmask[MAX_PATH], szName[MAX_PATH], *pszActive;
  52. ENUMSKIN es;
  53. bActiveFound = FALSE;
  54. bTerminated = FALSE;
  55. if (*config_skin)
  56. {
  57. pszActive = PathFindFileNameW(config_skin);
  58. if (pszActive != config_skin && BuildFullPath(SKINDIR, config_skin, szName, sizeof(szName)/sizeof(wchar_t)))
  59. {
  60. INT cr = ComparePath(szName, pszActive, SKINDIR);
  61. if(cr && CSTR_EQUAL != cr && PathFileExistsW(szName))
  62. {
  63. if (FillEnumRec(&es, config_skin, FALSE, szName, sizeof(szName)/sizeof(wchar_t), NULL))
  64. {
  65. es.bActive = TRUE;
  66. bActiveFound = TRUE;
  67. if (!fnEnumSkin(&es, user)) return FALSE;
  68. }
  69. }
  70. }
  71. }
  72. else pszActive = NULL;
  73. PathCombineW(dirmask, SKINDIR, L"*");
  74. h = FindFirstFileW(dirmask,&d);
  75. if (h != INVALID_HANDLE_VALUE)
  76. {
  77. do
  78. {
  79. if (FillEnumRec(&es, d.cFileName, (FILE_ATTRIBUTE_DIRECTORY & d.dwFileAttributes), szName, sizeof(szName)/sizeof(wchar_t), (bActiveFound) ? NULL : pszActive))
  80. {
  81. if (es.bActive) bActiveFound = TRUE;
  82. if (!fnEnumSkin(&es, user))
  83. {
  84. bTerminated = TRUE;
  85. break;
  86. }
  87. }
  88. } while (FindNextFileW(h,&d));
  89. FindClose(h);
  90. }
  91. if(!CLASSIC_NAME[0])getStringW(IDS_CLASSIC_SKIN_NAME,CLASSIC_NAME,64);
  92. es.pszFileName = NULL;
  93. es.pszName = CLASSIC_NAME;
  94. es.nType = SKIN_FILETYPE_EMBED;
  95. es.bActive = !bActiveFound;
  96. bTerminated = !fnEnumSkin(&es, user);
  97. return !bTerminated;
  98. }
  99. static int CALLBACK BrowseSkinCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
  100. {
  101. switch (uMsg)
  102. {
  103. case BFFM_INITIALIZED:
  104. {
  105. SetWindowTextW(hwnd, getStringW(IDS_P_SELECT_SKINDIR,NULL,0));
  106. SendMessageW(hwnd, BFFM_SETSELECTIONW, 1, (LPARAM)SKINDIR);
  107. }
  108. return 0;
  109. }
  110. return 0;
  111. }
  112. void SetDialogBoxFromFile(FILE *fp, HWND hwndDlg, int id)
  113. {
  114. bool utf8=false, utf16=false;
  115. unsigned char BOM[3] = {0, 0, 0};
  116. if (fread(BOM, 3, 1, fp) == 1 && BOM[0] == 0xEF && BOM[1] == 0xBB && BOM[2] == 0xBF)
  117. utf8 = true;
  118. else
  119. {
  120. fseek(fp, 0, SEEK_SET);
  121. if (fread(BOM, 2, 1, fp) == 1 && BOM[0] == 0xFF && BOM[1] == 0xFE)
  122. utf16=true;
  123. else
  124. fseek(fp, 0, SEEK_SET);
  125. }
  126. if (utf16)
  127. {
  128. wchar_t buffer[32768+1024] = {0},*p = buffer;
  129. for (;;)
  130. {
  131. fgetws(p,1024,fp);
  132. if (feof(fp)) break;
  133. if (p[wcslen(p)-1]==L'\n')
  134. p[wcslen(p)-1]=0;
  135. StringCchCatW(p,32768+1024,L"\r\n");
  136. p=p+wcslen(p);
  137. if (p-buffer > 32768) break;
  138. }
  139. buffer[32767]=0;
  140. SetDlgItemTextW(hwndDlg,id,buffer);
  141. }
  142. else
  143. {
  144. char buffer[32768+1024] = {0}, *p = buffer;
  145. for (;;)
  146. {
  147. fgets(p,1024,fp);
  148. if (feof(fp)) break;
  149. if (p[lstrlenA(p)-1]=='\n')
  150. p[lstrlenA(p)-1]=0;
  151. StringCchCatA(p,32768+1024,"\r\n");
  152. p=p+lstrlenA(p);
  153. if (p-buffer > 32768) break;
  154. }
  155. buffer[32767]=0;
  156. if (utf8)
  157. SetDlgItemTextW(hwndDlg,id,AutoWide(buffer, CP_UTF8));
  158. else
  159. SetDlgItemTextA(hwndDlg,id,buffer);
  160. }
  161. }
  162. static void _setreadme(HWND hwndDlg)
  163. {
  164. if (config_skin[0])
  165. {
  166. LRESULT ipcRet;
  167. if ((ipcRet=SendMessageW(hMainWindow,WM_WA_IPC,0,IPC_GETSKININFOW)) > 65536)
  168. {
  169. SetDlgItemTextW(hwndDlg,IDC_EDIT1,(const wchar_t *)ipcRet);
  170. }
  171. else if ((ipcRet=SendMessageW(hMainWindow,WM_WA_IPC,0,IPC_GETSKININFO)) > 65536)
  172. {
  173. SetDlgItemTextA(hwndDlg,IDC_EDIT1,(const char*)ipcRet);
  174. }
  175. else
  176. {
  177. wchar_t s[MAX_PATH]={0};
  178. PathCombineW(s, skin_directory, L"readme.txt");
  179. FILE *fp=_wfopen(s,L"rt");
  180. if (!fp)
  181. {
  182. PathCombineW(s, skin_directory, L"read me.txt");
  183. fp=_wfopen(s,L"rt");
  184. }
  185. if (!fp)
  186. {
  187. PathCombineW(s, skin_directory, L"file_id.diz");
  188. fp=_wfopen(s,L"rt");
  189. }
  190. if (!fp)
  191. {
  192. WIN32_FIND_DATAW d;
  193. PathCombineW(s, skin_directory, L"*.txt");
  194. HANDLE h = FindFirstFileW(s,&d);
  195. s[0]=0;
  196. if (h != INVALID_HANDLE_VALUE)
  197. {
  198. do
  199. {
  200. if (_wcsicmp(d.cFileName,L"pledit.txt") &&
  201. _wcsicmp(d.cFileName,L"viscolor.txt") &&
  202. _wcsicmp(d.cFileName,L"region.txt"))
  203. {
  204. PathCombineW(s, skin_directory, d.cFileName);
  205. break;
  206. }
  207. } while (FindNextFileW(h,&d));
  208. FindClose(h);
  209. if (s && L'\0' == *s) fp=_wfopen(s,L"rb");
  210. }
  211. }
  212. if (fp)
  213. {
  214. SetDialogBoxFromFile(fp, hwndDlg, IDC_EDIT1);
  215. fclose(fp);
  216. }
  217. else
  218. SetDlgItemTextW(hwndDlg,IDC_EDIT1,getStringW(IDS_P_SKIN_NO_INFO_FOUND,NULL,0));
  219. }
  220. }
  221. else
  222. {
  223. char buf[256]={0}, form[64]={0};
  224. StringCchPrintfA(buf,256, getString(IDS_CLASSIC_BASE_SKIN_VERSION,form,64),app_version);
  225. SetDlgItemTextA(hwndDlg,IDC_EDIT1,buf);
  226. }
  227. }
  228. static BOOL CALLBACK renameSkinProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  229. {
  230. switch (uMsg)
  231. {
  232. case WM_INITDIALOG:
  233. SetDlgItemTextW(hwndDlg,IDC_OLD,rename_skin);
  234. SetDlgItemTextW(hwndDlg,IDC_NEW,rename_skin);
  235. return TRUE;
  236. case WM_COMMAND:
  237. switch (LOWORD(wParam))
  238. {
  239. case IDOK:
  240. GetDlgItemTextW(hwndDlg,IDC_NEW,rename_skin,MAX_PATH);
  241. EndDialog(hwndDlg,!!rename_skin[0]);
  242. return 0;
  243. case IDCANCEL:
  244. EndDialog(hwndDlg,0);
  245. return 0;
  246. }
  247. return 0;
  248. }
  249. return 0;
  250. }
  251. static void SkinDeleteSkin(HWND hwndDlg, LRESULT x)
  252. {
  253. wchar_t skin[MAX_PATH] = {0};
  254. int x2 = SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_GETCURSEL,0,0);
  255. SendDlgItemMessageW(hwndDlg,IDC_SELBOX,LB_GETTEXT,(x!=-1?x:x2),(LPARAM)skin);
  256. switch (SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_GETITEMDATA,(x!=-1?x:x2),0))
  257. {
  258. case SKIN_FILETYPE_ZIP: StringCchCatW(skin,MAX_PATH, L".zip"); break;
  259. case SKIN_FILETYPE_WSZ: StringCchCatW(skin,MAX_PATH, L".wsz"); break;
  260. case SKIN_FILETYPE_WAL: StringCchCatW(skin,MAX_PATH, L".wal"); break;
  261. default: break;
  262. }
  263. if (skin[0] && _wcsicmp(skin,CLASSIC_NAME) && _wcsicmp(skin,MODERN_SKIN_NAME) &&
  264. _wcsicmp(skin,BENTO_SKIN_NAME) && _wcsicmp(skin,BIG_BENTO_SKIN_NAME))
  265. {
  266. wchar_t buf[2048] = {0};
  267. StringCchPrintfW(buf, 2048, getStringW(IDS_P_SKINS_DELETESKIN_PROMPT,NULL,0),skin);
  268. if (MessageBoxW(hwndDlg,buf,getStringW(IDS_P_SKINS_DELETESKIN,NULL,0),MB_YESNO|MB_ICONQUESTION) == IDYES)
  269. {
  270. PathCombineW(buf, SKINDIR, skin);
  271. IFileTypeRegistrar *registrar=0;
  272. if (GetRegistrar(&registrar, true) == 0 && registrar)
  273. {
  274. registrar->DeleteItem(buf);
  275. registrar->CleanupDirectory(buf);
  276. registrar->Release();
  277. }
  278. SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_DELETESTRING,(x!=-1?x:x2),0);
  279. // check if it's the current skin and if so reset to 'classic' and refresh
  280. if (((x == x2) && !lstrcmpiW(config_skin, skin)) || x == -1)
  281. {
  282. SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_SETCURSEL,0,0);
  283. config_skin[0]=0;
  284. SendMessageW(hMainWindow,WM_COMMAND,WINAMP_REFRESHSKIN,0);
  285. _setreadme(hwndDlg);
  286. }
  287. }
  288. }
  289. }
  290. static BOOL CALLBACK AddSkinToListBox(ENUMSKIN *pes, void *user)
  291. {
  292. int index;
  293. index = SendMessageW((HWND)user, LB_ADDSTRING, 0, (LPARAM)pes->pszName);
  294. if (LB_ERR != index)
  295. {
  296. SendMessageW((HWND)user, LB_SETITEMDATA, index, (LPARAM)pes->nType);
  297. if (pes->bActive) SendMessageW((HWND)user, LB_SETCURSEL, index, 0);
  298. }
  299. return TRUE;
  300. }
  301. static void SkinRenameSkin(HWND hwndDlg, LRESULT x, int* timer_active)
  302. {
  303. int x2 = SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_GETCURSEL,0,0);
  304. int nType = SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_GETITEMDATA,(x!=-1?x:x2),0);
  305. SendDlgItemMessageW(hwndDlg,IDC_SELBOX,LB_GETTEXT,(x!=-1?x:x2),(LPARAM)rename_skin);
  306. if (rename_skin[0] && _wcsicmp(rename_skin,CLASSIC_NAME) &&
  307. (nType || (_wcsicmp(rename_skin,MODERN_SKIN_NAME) &&
  308. _wcsicmp(rename_skin,BENTO_SKIN_NAME) &&
  309. _wcsicmp(rename_skin,BIG_BENTO_SKIN_NAME))))
  310. {
  311. wchar_t oldskin[MAX_PATH] = {0};
  312. StringCchCopyW(oldskin, MAX_PATH,rename_skin);
  313. if (LPDialogBoxW(IDD_RENAMESKIN,hwndDlg,renameSkinProc) && wcscmp(oldskin,rename_skin))
  314. {
  315. wchar_t oldname[MAX_PATH] = {0}, newname[MAX_PATH] = {0};
  316. PathCombineW(oldname, SKINDIR, oldskin);
  317. PathCombineW(newname, SKINDIR, rename_skin);
  318. switch (nType)
  319. {
  320. case SKIN_FILETYPE_ZIP: StringCchCatW(oldname,MAX_PATH, L".zip"); StringCchCatW(newname,MAX_PATH, L".zip"); break;
  321. case SKIN_FILETYPE_WSZ: StringCchCatW(oldname,MAX_PATH, L".wsz"); StringCchCatW(newname,MAX_PATH, L".wsz"); break;
  322. case SKIN_FILETYPE_WAL: StringCchCatW(oldname,MAX_PATH, L".wal"); StringCchCatW(newname,MAX_PATH, L".wal"); break;
  323. default: break;
  324. }
  325. IFileTypeRegistrar *registrar=0;
  326. if (GetRegistrar(&registrar, true) == 0 && registrar)
  327. {
  328. if (SUCCEEDED(registrar->RenameItem(oldname,newname, FALSE)))
  329. {
  330. SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_DELETESTRING,(x!=-1?x:x2),0);
  331. SendDlgItemMessageW(hwndDlg,IDC_SELBOX,LB_INSERTSTRING,(x!=-1?x:x2),(LPARAM)rename_skin);
  332. SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_SETITEMDATA,(x!=-1?x:x2), nType);
  333. // check if it's the current skin and if so reset to 'classic' and refresh
  334. if (((x == x2) && !lstrcmpiW(config_skin, newname)) || x == -1)
  335. {
  336. SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_SETCURSEL,(x!=-1?x:x2),0);
  337. KillTimer(hwndDlg,1);
  338. SetTimer(hwndDlg,1,250,NULL);
  339. *timer_active=1;
  340. }
  341. }
  342. else
  343. {
  344. LPMessageBox(hwndDlg, IDS_P_SKINS_RN_ERR, IDS_P_SKINS_RN_ERR_CAP, MB_OK);
  345. }
  346. registrar->Release();
  347. }
  348. }
  349. }
  350. }
  351. static LRESULT WINAPI list_newWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  352. {
  353. if(uMsg == WM_RBUTTONUP)
  354. {
  355. PostMessageW(GetParent(hwndDlg),WM_USER+0x123,0,0);
  356. }
  357. else if(uMsg == WM_KEYDOWN && wParam == VK_DELETE)
  358. {
  359. SkinDeleteSkin(GetParent(hwndDlg),-1);
  360. }
  361. return CallWindowProcW(list_oldWndProc,hwndDlg,uMsg,wParam,lParam);
  362. }
  363. INT_PTR CALLBACK SkinProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  364. {
  365. static int timer_active;
  366. hi helpinfo[]={{IDC_SELBOX,IDS_P_SK_SEL},
  367. {IDC_RANDOM,IDS_P_SK_RND},
  368. {IDC_CHDIR,IDS_P_SK_CHDR},
  369. {IDC_SKIN_INSTALL_PROMPT,IDS_P_SK_PROMPT}};
  370. DO_HELP();
  371. switch (uMsg)
  372. {
  373. case WM_NOTIFYFORMAT:
  374. {
  375. return NFR_UNICODE;
  376. }
  377. case WM_INITDIALOG:
  378. {
  379. HWND listWindow = GetDlgItem(hwndDlg,IDC_SELBOX);
  380. if (NULL != listWindow)
  381. {
  382. SendMessageW(listWindow, CCM_SETUNICODEFORMAT, TRUE, 0);
  383. list_oldWndProc=(WNDPROC)SetWindowLongPtrW(listWindow,GWLP_WNDPROC,(LONG_PTR)list_newWndProc);
  384. DirectMouseWheel_EnableConvertToMouseWheel(listWindow, TRUE);
  385. }
  386. CheckDlgButton(hwndDlg, IDC_SKIN_INSTALL_PROMPT, config_skin_prompt);
  387. link_startsubclass(hwndDlg, IDC_WINAMPLINK);
  388. }
  389. case WM_USER+50:
  390. {
  391. int index, en, modern = 0, bento = 0;
  392. wchar_t selected[MAX_PATH] = {0};
  393. HWND hw = GetDlgItem(hwndDlg,IDC_SELBOX);
  394. SendMessageW(hw,WM_SETREDRAW,FALSE,0);
  395. EnumerateSkins(AddSkinToListBox, hw);
  396. index = (INT)SendMessageW(hw,LB_GETCURSEL,0,0);
  397. if (LB_ERR == index || LB_ERR == SendMessageW(hw, LB_GETTEXT, index, (LPARAM)selected))
  398. selected[0] = 0x00;
  399. index = (INT)SendMessageW(hw, LB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)CLASSIC_NAME);
  400. if (LB_ERR != index)
  401. {
  402. SendMessageW(hw, LB_DELETESTRING, index, 0);
  403. SendMessageW(hw, LB_INSERTSTRING, 0, (LPARAM)CLASSIC_NAME);
  404. }
  405. index = (INT)SendMessageW(hw, LB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)MODERN_SKIN_NAME);
  406. if (LB_ERR != index)
  407. {
  408. SendMessageW(hw, LB_DELETESTRING, index, 0);
  409. SendMessageW(hw, LB_INSERTSTRING, 1, (LPARAM)MODERN_SKIN_NAME);
  410. modern = 1;
  411. }
  412. index = (INT)SendMessageW(hw, LB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)BENTO_SKIN_NAME);
  413. if (LB_ERR != index)
  414. {
  415. SendMessageW(hw, LB_DELETESTRING, index, 0);
  416. SendMessageW(hw, LB_INSERTSTRING, 1 + modern, (LPARAM)BENTO_SKIN_NAME);
  417. bento = 1;
  418. }
  419. index = (INT)SendMessageW(hw, LB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)BIG_BENTO_SKIN_NAME);
  420. if (LB_ERR != index)
  421. {
  422. SendMessageW(hw, LB_DELETESTRING, index, 0);
  423. SendMessageW(hw, LB_INSERTSTRING, 1 + modern + bento, (LPARAM)BIG_BENTO_SKIN_NAME);
  424. }
  425. index = (*selected) ? (INT)SendMessageW(hw, LB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)selected) : LB_ERR;
  426. if (LB_ERR == index) index = 0;
  427. SendMessageW(hw,LB_SETCURSEL, index, 0);
  428. en = config_skin[0] && _wcsicmp(config_skin,MODERN_SKIN_NAME) &&
  429. _wcsicmp(config_skin,BENTO_SKIN_NAME) &&
  430. _wcsicmp(config_skin,BIG_BENTO_SKIN_NAME);
  431. EnableWindow(GetDlgItem(hwndDlg,IDC_RENAME_SKIN),en);
  432. EnableWindow(GetDlgItem(hwndDlg,IDC_DELETE_SKIN),en);
  433. SendMessageW(hw,WM_SETREDRAW,TRUE,0);
  434. CheckDlgButton(hwndDlg,IDC_RANDOM,config_randskin);
  435. _setreadme(hwndDlg);
  436. return FALSE;
  437. }
  438. case WM_USER+0x123:
  439. {
  440. HMENU h=GetSubMenu(GetSubMenu(top_menu,5),0);
  441. if (h)
  442. {
  443. POINT p,ps;
  444. GetCursorPos(&p);
  445. ps=p;
  446. ScreenToClient(GetDlgItem(hwndDlg,IDC_SELBOX),&ps);
  447. LRESULT x=SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_ITEMFROMPOINT,0,MAKELPARAM(ps.x,ps.y));
  448. if (HIWORD(x)==0 && (x=LOWORD(x)) >= 0)
  449. {
  450. bool allowo=x > 0;
  451. wchar_t skin[MAX_PATH] = {0};
  452. int nType = SendDlgItemMessageW(hwndDlg,IDC_SELBOX,LB_GETITEMDATA,x,0);
  453. SendDlgItemMessageW(hwndDlg,IDC_SELBOX,LB_GETTEXT,x,(LPARAM)skin);
  454. if (allowo &&
  455. (!_wcsicmp(skin,MODERN_SKIN_NAME) || !_wcsicmp(skin,BENTO_SKIN_NAME) ||
  456. !_wcsicmp(skin,BIG_BENTO_SKIN_NAME)) && SKIN_FILETYPE_DIR == nType)
  457. allowo=0;
  458. EnableMenuItem(h,2,MF_BYPOSITION|(allowo?MF_ENABLED:MF_GRAYED));
  459. EnableMenuItem(h,3,MF_BYPOSITION|(allowo?MF_ENABLED:MF_GRAYED));
  460. //int sel=DoTrackPopup(h,TPM_RETURNCMD|TPM_NONOTIFY|TPM_RIGHTBUTTON,p.x,p.y,hwndDlg);
  461. int sel=TrackPopupMenu(h,TPM_RETURNCMD|TPM_NONOTIFY|TPM_RIGHTBUTTON,p.x,p.y,0,hwndDlg,NULL);
  462. if (sel)
  463. {
  464. if (sel == ID_PREFS_SKIN_SWITCHTOSKIN)
  465. {
  466. SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_SETCURSEL,LOWORD(x),0);
  467. KillTimer(hwndDlg,1);
  468. SetTimer(hwndDlg,1,250,NULL);
  469. timer_active=1;
  470. }
  471. else if (sel == ID_PREFS_SKIN_RENAMESKIN)
  472. {
  473. SkinRenameSkin(hwndDlg, x, &timer_active);
  474. }
  475. else if (sel == ID_PREFS_SKIN_DELETESKIN)
  476. {
  477. SkinDeleteSkin(hwndDlg,x);
  478. }
  479. }
  480. }
  481. }
  482. return 0;
  483. }
  484. case WM_COMMAND:
  485. {
  486. switch (LOWORD(wParam))
  487. {
  488. case IDC_SKIN_INSTALL_PROMPT:
  489. {
  490. config_skin_prompt = !config_skin_prompt;
  491. return 0;
  492. }
  493. case IDC_RENAME_SKIN:
  494. {
  495. SkinRenameSkin(hwndDlg, -1, &timer_active);
  496. return 0;
  497. }
  498. case IDC_DELETE_SKIN:
  499. {
  500. SkinDeleteSkin(hwndDlg,-1);
  501. return 0;
  502. }
  503. case IDC_WINAMPLINK:
  504. {
  505. myOpenURLWithFallback(hwndDlg,L"http://www.google.com/search?q=%22winamp+skins%22", L"http://www.google.com/search?q=%22winamp+skins%22");
  506. return 0;
  507. }
  508. case IDC_RANDOM:
  509. {
  510. config_randskin = IsDlgButtonChecked(hwndDlg,IDC_RANDOM)?1:0;
  511. return 0;
  512. }
  513. case IDC_CHDIR:
  514. {
  515. BROWSEINFOW bi = {0};
  516. bi.hwndOwner = hwndDlg;
  517. bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
  518. bi.lpfn = BrowseSkinCallbackProc;
  519. ITEMIDLIST *idlist = SHBrowseForFolderW(&bi);
  520. if (idlist) {
  521. wchar_t path[MAX_PATH] = {0};
  522. SHGetPathFromIDListW(idlist, path);
  523. Shell_Free(idlist);
  524. if(!PathIsRootW(path)) {
  525. wchar_t orig[MAX_PATH] = {0};
  526. StringCchCopyW(orig, MAX_PATH, SKINDIR);
  527. StringCchCopyW(SKINDIR, MAX_PATH, path);
  528. _w_sW("SkinDir", SKINDIR);
  529. wchar_t message[2048] = {0};
  530. StringCchPrintfW(message,2048,getStringW(IDS_SKIN_DIR_MOVE_MESSAGE,NULL,0),orig,SKINDIR);
  531. if(MessageBoxW(hwndDlg, message, getStringW(IDS_SKIN_DIR_MOVE,NULL,0),MB_YESNO|MB_ICONQUESTION)==IDYES)
  532. {
  533. IFileTypeRegistrar *registrar=0;
  534. if (GetRegistrar(&registrar, true) == 0 && registrar)
  535. {
  536. registrar->MoveDirectoryContents(orig,SKINDIR);
  537. registrar->Release();
  538. }
  539. }
  540. SendMessageW(GetDlgItem(hwndDlg,IDC_SELBOX),LB_RESETCONTENT,0,0);
  541. SendMessageW(hwndDlg,WM_USER+50,0,0);
  542. }
  543. else {
  544. wchar_t message[512] = {0};
  545. MessageBoxW(hwndDlg, getStringW(IDS_DIR_MOVE_ERROR, message, 512),
  546. getStringW(IDS_SKIN_DIR_MOVE,NULL,0), MB_OK|MB_ICONEXCLAMATION);
  547. }
  548. }
  549. return FALSE;
  550. }
  551. case IDC_SELBOX:
  552. if (HIWORD(wParam) == LBN_DBLCLK)
  553. {
  554. SendMessageW(hwndDlg,WM_COMMAND,IDOK,0);
  555. }
  556. if (HIWORD(wParam) == LBN_SELCHANGE)
  557. {
  558. KillTimer(hwndDlg,1);
  559. SetTimer(hwndDlg,1,250,NULL);
  560. timer_active=1;
  561. }
  562. return FALSE;
  563. }
  564. return FALSE;
  565. }
  566. case WM_DESTROY:
  567. {
  568. HWND listWindow = GetDlgItem(hwndDlg,IDC_SELBOX);
  569. if (NULL != listWindow)
  570. {
  571. DirectMouseWheel_EnableConvertToMouseWheel(listWindow, FALSE);
  572. }
  573. if (!timer_active) return 0;
  574. }
  575. case WM_TIMER:
  576. {
  577. wchar_t oldbuf[MAX_PATH] = {0};
  578. int x = SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_GETCURSEL,0,0);
  579. timer_active=0;
  580. KillTimer(hwndDlg,1);
  581. StringCchCopyW(oldbuf,MAX_PATH,config_skin);
  582. SendDlgItemMessageW(hwndDlg,IDC_SELBOX,LB_GETTEXT,x,(LPARAM)config_skin);
  583. switch (SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_GETITEMDATA,x,0))
  584. {
  585. case SKIN_FILETYPE_ZIP: StringCchCatW(config_skin,MAX_PATH, L".zip"); break;
  586. case SKIN_FILETYPE_WSZ: StringCchCatW(config_skin,MAX_PATH, L".wsz"); break;
  587. case SKIN_FILETYPE_WAL: StringCchCatW(config_skin,MAX_PATH, L".wal"); break;
  588. default: break;
  589. }
  590. if (!_wcsicmp(config_skin,CLASSIC_NAME)) config_skin[0]=0;
  591. {
  592. int en = config_skin[0] && _wcsicmp(config_skin,MODERN_SKIN_NAME) &&
  593. _wcsicmp(config_skin,BENTO_SKIN_NAME) &&
  594. _wcsicmp(config_skin,BIG_BENTO_SKIN_NAME);
  595. EnableWindow(GetDlgItem(hwndDlg,IDC_RENAME_SKIN),en);
  596. EnableWindow(GetDlgItem(hwndDlg,IDC_DELETE_SKIN),en);
  597. }
  598. if (_wcsicmp(oldbuf,config_skin))
  599. {
  600. SendMessageW(hMainWindow,WM_COMMAND,WINAMP_REFRESHSKIN,0);
  601. _setreadme(hwndDlg);
  602. }
  603. }
  604. return FALSE;
  605. }
  606. if (uMsg == WM_COMMAND && LOWORD(wParam)==IDC_PLUGINVERS)
  607. {
  608. myOpenURLWithFallback(hwndDlg, L"http://www.google.com/search?q=%22winamp+plugins%22", L"http://www.winamp.com/plugins");
  609. }
  610. link_handledraw(hwndDlg,uMsg,wParam,lParam);
  611. const int controls[] =
  612. {
  613. IDC_EDIT1,
  614. };
  615. if (FALSE != DirectMouseWheel_ProcessDialogMessage(hwndDlg, uMsg, wParam, lParam, controls, ARRAYSIZE(controls)))
  616. {
  617. return TRUE;
  618. }
  619. return 0;
  620. } // skins