driveui.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  1. /*
  2. * Drive management UI code
  3. *
  4. * Copyright 2003 Mark Westcott
  5. * Copyright 2004 Chris Morgan
  6. * Copyright 2003-2004 Mike Hearn
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  21. *
  22. */
  23. #include <stdio.h>
  24. #define WIN32_LEAN_AND_MEAN
  25. #define COBJMACROS
  26. #include <windows.h>
  27. #include <shellapi.h>
  28. #include <objbase.h>
  29. #include <shlguid.h>
  30. #include <shlwapi.h>
  31. #include <shlobj.h>
  32. #include <wine/unicode.h>
  33. #include <wine/debug.h>
  34. #include "winecfg.h"
  35. #include "resource.h"
  36. WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
  37. #define BOX_MODE_DEVICE 1
  38. #define BOX_MODE_NORMAL 2
  39. static BOOL advanced = FALSE;
  40. static BOOL updating_ui = FALSE;
  41. static struct drive* current_drive;
  42. static void update_controls(HWND dialog);
  43. static DWORD driveui_msgbox (HWND parent, UINT messageId, DWORD flags)
  44. {
  45. WCHAR* caption = load_string (IDS_WINECFG_TITLE);
  46. WCHAR* text = load_string (messageId);
  47. DWORD result = MessageBoxW (parent, text, caption, flags);
  48. HeapFree (GetProcessHeap(), 0, caption);
  49. HeapFree (GetProcessHeap(), 0, text);
  50. return result;
  51. }
  52. /**** listview helper functions ****/
  53. /* clears the item at index in the listview */
  54. static void lv_clear_curr_select(HWND dialog, int index)
  55. {
  56. LVITEMW item;
  57. item.mask = LVIF_STATE;
  58. item.state = 0;
  59. item.stateMask = LVIS_SELECTED;
  60. SendDlgItemMessageW( dialog, IDC_LIST_DRIVES, LVM_SETITEMSTATE, index, (LPARAM)&item );
  61. }
  62. /* selects the item at index in the listview */
  63. static void lv_set_curr_select(HWND dialog, int index)
  64. {
  65. LVITEMW item;
  66. /* no more than one item can be selected in our listview */
  67. lv_clear_curr_select(dialog, -1);
  68. item.mask = LVIF_STATE;
  69. item.state = LVIS_SELECTED;
  70. item.stateMask = LVIS_SELECTED;
  71. SendDlgItemMessageW( dialog, IDC_LIST_DRIVES, LVM_SETITEMSTATE, index, (LPARAM)&item );
  72. }
  73. /* returns the currently selected item in the listview */
  74. static int lv_get_curr_select(HWND dialog)
  75. {
  76. return SendDlgItemMessageW(dialog, IDC_LIST_DRIVES, LVM_GETNEXTITEM, -1, LVNI_SELECTED);
  77. }
  78. /* sets the item in the listview at item->iIndex */
  79. static void lv_set_item(HWND dialog, LVITEMW *item)
  80. {
  81. SendDlgItemMessageW(dialog, IDC_LIST_DRIVES, LVM_SETITEMW, 0, (LPARAM) item);
  82. }
  83. /* sets specified item's text */
  84. static void lv_set_item_text(HWND dialog, int item, int subItem, WCHAR *text)
  85. {
  86. LVITEMW lvItem;
  87. if (item < 0 || subItem < 0) return;
  88. lvItem.mask = LVIF_TEXT;
  89. lvItem.iItem = item;
  90. lvItem.iSubItem = subItem;
  91. lvItem.pszText = text;
  92. lvItem.cchTextMax = lstrlenW(lvItem.pszText);
  93. lv_set_item(dialog, &lvItem);
  94. }
  95. /* inserts an item into the listview */
  96. static void lv_insert_item(HWND dialog, LVITEMW *item)
  97. {
  98. SendDlgItemMessageW(dialog, IDC_LIST_DRIVES, LVM_INSERTITEMW, 0, (LPARAM) item);
  99. }
  100. /* retrieve the item at index item->iIndex */
  101. static void lv_get_item(HWND dialog, LVITEMW *item)
  102. {
  103. SendDlgItemMessageW(dialog, IDC_LIST_DRIVES, LVM_GETITEMW, 0, (LPARAM) item);
  104. }
  105. static void set_advanced(HWND dialog)
  106. {
  107. int state;
  108. WCHAR text[256];
  109. if (advanced)
  110. {
  111. state = SW_NORMAL;
  112. LoadStringW(GetModuleHandleW(NULL), IDS_HIDE_ADVANCED, text, 256);
  113. }
  114. else
  115. {
  116. state = SW_HIDE;
  117. LoadStringW(GetModuleHandleW(NULL), IDS_SHOW_ADVANCED, text, 256);
  118. }
  119. ShowWindow(GetDlgItem(dialog, IDC_EDIT_DEVICE), state);
  120. ShowWindow(GetDlgItem(dialog, IDC_STATIC_DEVICE), state);
  121. ShowWindow(GetDlgItem(dialog, IDC_EDIT_LABEL), state);
  122. ShowWindow(GetDlgItem(dialog, IDC_STATIC_LABEL), state);
  123. ShowWindow(GetDlgItem(dialog, IDC_BUTTON_BROWSE_DEVICE), state);
  124. ShowWindow(GetDlgItem(dialog, IDC_EDIT_SERIAL), state);
  125. ShowWindow(GetDlgItem(dialog, IDC_STATIC_SERIAL), state);
  126. ShowWindow(GetDlgItem(dialog, IDC_COMBO_TYPE), state);
  127. ShowWindow(GetDlgItem(dialog, IDC_STATIC_TYPE), state);
  128. /* update the button text based on the state */
  129. SetWindowTextW(GetDlgItem(dialog, IDC_BUTTON_SHOW_HIDE_ADVANCED), text);
  130. }
  131. struct drive_typemap {
  132. unsigned int sCode;
  133. UINT idDesc;
  134. };
  135. static const struct drive_typemap type_pairs[] = {
  136. { DRIVE_UNKNOWN, IDS_DRIVE_UNKNOWN },
  137. { DRIVE_FIXED, IDS_DRIVE_FIXED },
  138. { DRIVE_REMOTE, IDS_DRIVE_REMOTE },
  139. { DRIVE_REMOVABLE, IDS_DRIVE_REMOVABLE },
  140. { DRIVE_CDROM, IDS_DRIVE_CDROM }
  141. };
  142. #define DRIVE_TYPE_DEFAULT 0
  143. static void enable_labelserial_box(HWND dialog, int mode)
  144. {
  145. WINE_TRACE("mode=%d\n", mode);
  146. switch (mode)
  147. {
  148. case BOX_MODE_DEVICE:
  149. /* FIXME: enable device editing */
  150. disable(IDC_EDIT_DEVICE);
  151. disable(IDC_BUTTON_BROWSE_DEVICE);
  152. disable(IDC_EDIT_SERIAL);
  153. disable(IDC_EDIT_LABEL);
  154. break;
  155. case BOX_MODE_NORMAL:
  156. disable(IDC_EDIT_DEVICE);
  157. disable(IDC_BUTTON_BROWSE_DEVICE);
  158. enable(IDC_EDIT_SERIAL);
  159. enable(IDC_EDIT_LABEL);
  160. break;
  161. }
  162. }
  163. static int fill_drives_list(HWND dialog)
  164. {
  165. int count = 0;
  166. BOOL drivec_present = FALSE;
  167. int i;
  168. int prevsel = -1;
  169. WINE_TRACE("\n");
  170. updating_ui = TRUE;
  171. prevsel = lv_get_curr_select(dialog);
  172. /* Clear the listbox */
  173. SendDlgItemMessageW(dialog, IDC_LIST_DRIVES, LVM_DELETEALLITEMS, 0, 0);
  174. for(i = 0; i < 26; i++)
  175. {
  176. LVITEMW item;
  177. WCHAR *path;
  178. char letter[4];
  179. /* skip over any unused drives */
  180. if (!drives[i].in_use)
  181. continue;
  182. if (drives[i].letter == 'C')
  183. drivec_present = TRUE;
  184. letter[0] = 'A' + i;
  185. letter[1] = ':';
  186. letter[2] = 0;
  187. item.mask = LVIF_TEXT | LVIF_PARAM;
  188. item.iItem = count;
  189. item.iSubItem = 0;
  190. item.pszText = strdupU2W(letter);
  191. item.cchTextMax = lstrlenW(item.pszText);
  192. item.lParam = (LPARAM) &drives[i];
  193. lv_insert_item(dialog, &item);
  194. HeapFree(GetProcessHeap(), 0, item.pszText);
  195. path = strdupU2W(drives[i].unixpath);
  196. lv_set_item_text(dialog, count, 1, path);
  197. HeapFree(GetProcessHeap(), 0, path);
  198. count++;
  199. }
  200. WINE_TRACE("loaded %d drives\n", count);
  201. /* show the warning if there is no Drive C */
  202. if (!drivec_present)
  203. ShowWindow(GetDlgItem(dialog, IDS_DRIVE_NO_C), SW_NORMAL);
  204. else
  205. ShowWindow(GetDlgItem(dialog, IDS_DRIVE_NO_C), SW_HIDE);
  206. lv_set_curr_select(dialog, prevsel == -1 ? 0 : prevsel);
  207. updating_ui = FALSE;
  208. return count;
  209. }
  210. static void on_options_click(HWND dialog)
  211. {
  212. if (IsDlgButtonChecked(dialog, IDC_SHOW_DOT_FILES) == BST_CHECKED)
  213. set_reg_key(config_key, "", "ShowDotFiles", "Y");
  214. else
  215. set_reg_key(config_key, "", "ShowDotFiles", "N");
  216. SendMessageW(GetParent(dialog), PSM_CHANGED, 0, 0);
  217. }
  218. static INT_PTR CALLBACK drivechoose_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  219. {
  220. static int i, sel;
  221. char c;
  222. char drive[] = "X:";
  223. switch(uMsg)
  224. {
  225. case WM_INITDIALOG:
  226. {
  227. ULONG mask = ~drive_available_mask(0); /* the mask is now which drives aren't available */
  228. for( c = 'A'; c<= 'Z'; c++){
  229. drive[0] = c;
  230. if(!( mask & (1 << (c - 'A'))))
  231. SendDlgItemMessageA( hwndDlg, IDC_DRIVESA2Z, CB_ADDSTRING, 0, (LPARAM) drive);
  232. }
  233. drive[0] = lParam;
  234. SendDlgItemMessageA( hwndDlg, IDC_DRIVESA2Z, CB_SELECTSTRING, 0, (LPARAM) drive);
  235. return TRUE;
  236. }
  237. case WM_COMMAND:
  238. if(HIWORD(wParam) != BN_CLICKED) break;
  239. switch (LOWORD(wParam))
  240. {
  241. case IDOK:
  242. i = SendDlgItemMessageA( hwndDlg, IDC_DRIVESA2Z, CB_GETCURSEL, 0, 0);
  243. if( i != CB_ERR){
  244. SendDlgItemMessageA( hwndDlg, IDC_DRIVESA2Z, CB_GETLBTEXT, i, (LPARAM) drive);
  245. sel = drive[0];
  246. } else
  247. sel = -1;
  248. EndDialog(hwndDlg, sel);
  249. return TRUE;
  250. case IDCANCEL:
  251. EndDialog(hwndDlg, -1);
  252. return TRUE;
  253. }
  254. }
  255. return FALSE;
  256. }
  257. static void on_add_click(HWND dialog)
  258. {
  259. /* we should allocate a drive letter automatically. We also need
  260. some way to let the user choose the mapping point, for now we
  261. will just force them to enter a path automatically, with / being
  262. the default. In future we should be able to temporarily map /
  263. then invoke the directory chooser dialog. */
  264. char new = 'C'; /* we skip A and B, they are historically floppy drives */
  265. ULONG mask = ~drive_available_mask(0); /* the mask is now which drives aren't available */
  266. int i, c;
  267. INT_PTR ret;
  268. while (mask & (1 << (new - 'A')))
  269. {
  270. new++;
  271. if (new > 'Z')
  272. {
  273. driveui_msgbox (dialog, IDS_DRIVE_LETTERS_EXCEEDED, MB_OK | MB_ICONEXCLAMATION);
  274. return;
  275. }
  276. }
  277. ret = DialogBoxParamW(0, MAKEINTRESOURCEW(IDD_DRIVECHOOSE), dialog, drivechoose_dlgproc, new);
  278. if( ret == -1) return;
  279. new = ret;
  280. WINE_TRACE("selected drive letter %c\n", new);
  281. if (new == 'C')
  282. {
  283. WCHAR label[64];
  284. LoadStringW(GetModuleHandleW(NULL), IDS_SYSTEM_DRIVE_LABEL, label, ARRAY_SIZE(label));
  285. add_drive(new, "../drive_c", NULL, label, 0, DRIVE_FIXED);
  286. }
  287. else add_drive(new, "/", NULL, NULL, 0, DRIVE_UNKNOWN);
  288. fill_drives_list(dialog);
  289. /* select the newly created drive */
  290. mask = ~drive_available_mask(0);
  291. c = 0;
  292. for (i = 0; i < 26; i++)
  293. {
  294. if ('A' + i == new) break;
  295. if ((1 << i) & mask) c++;
  296. }
  297. lv_set_curr_select(dialog, c);
  298. SetFocus(GetDlgItem(dialog, IDC_LIST_DRIVES));
  299. update_controls(dialog);
  300. SendMessageW(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
  301. }
  302. static void on_remove_click(HWND dialog)
  303. {
  304. int itemIndex;
  305. struct drive *drive;
  306. LVITEMW item;
  307. itemIndex = lv_get_curr_select(dialog);
  308. if (itemIndex == -1) return; /* no selection */
  309. item.mask = LVIF_PARAM;
  310. item.iItem = itemIndex;
  311. item.iSubItem = 0;
  312. lv_get_item(dialog, &item);
  313. drive = (struct drive *) item.lParam;
  314. WINE_TRACE("unixpath: %s\n", drive->unixpath);
  315. if (drive->letter == 'C')
  316. {
  317. DWORD result = driveui_msgbox (dialog, IDS_CONFIRM_DELETE_C, MB_YESNO | MB_ICONEXCLAMATION);
  318. if (result == IDNO) return;
  319. }
  320. delete_drive(drive);
  321. fill_drives_list(dialog);
  322. itemIndex = itemIndex - 1;
  323. if (itemIndex < 0) itemIndex = 0;
  324. lv_set_curr_select(dialog, itemIndex); /* previous item */
  325. SetFocus(GetDlgItem(dialog, IDC_LIST_DRIVES));
  326. update_controls(dialog);
  327. SendMessageW(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
  328. }
  329. static void update_controls(HWND dialog)
  330. {
  331. static const WCHAR emptyW[1];
  332. WCHAR *path;
  333. unsigned int type;
  334. char serial[16];
  335. int i, selection = -1;
  336. LVITEMW item;
  337. updating_ui = TRUE;
  338. i = lv_get_curr_select(dialog);
  339. if (i == -1)
  340. {
  341. /* no selection? let's select something for the user. this will re-enter */
  342. lv_set_curr_select(dialog, i);
  343. return;
  344. }
  345. item.mask = LVIF_PARAM;
  346. item.iItem = i;
  347. item.iSubItem = 0;
  348. lv_get_item(dialog, &item);
  349. current_drive = (struct drive *) item.lParam;
  350. WINE_TRACE("Updating sheet for drive %c\n", current_drive->letter);
  351. /* path */
  352. WINE_TRACE("set path control text to '%s'\n", current_drive->unixpath);
  353. path = strdupU2W(current_drive->unixpath);
  354. set_textW(dialog, IDC_EDIT_PATH, path);
  355. HeapFree(GetProcessHeap(), 0, path);
  356. /* drive type */
  357. type = current_drive->type;
  358. SendDlgItemMessageW(dialog, IDC_COMBO_TYPE, CB_RESETCONTENT, 0, 0);
  359. for (i = 0; i < ARRAY_SIZE(type_pairs); i++)
  360. {
  361. WCHAR driveDesc[64];
  362. LoadStringW(GetModuleHandleW(NULL), type_pairs[i].idDesc, driveDesc, ARRAY_SIZE(driveDesc));
  363. SendDlgItemMessageW (dialog, IDC_COMBO_TYPE, CB_ADDSTRING, 0, (LPARAM)driveDesc);
  364. if (type_pairs[i].sCode == type)
  365. {
  366. selection = i;
  367. }
  368. }
  369. if (selection == -1) selection = DRIVE_TYPE_DEFAULT;
  370. SendDlgItemMessageW(dialog, IDC_COMBO_TYPE, CB_SETCURSEL, selection, 0);
  371. EnableWindow( GetDlgItem( dialog, IDC_BUTTON_REMOVE ), (current_drive->letter != 'C') );
  372. EnableWindow( GetDlgItem( dialog, IDC_EDIT_PATH ), (current_drive->letter != 'C') );
  373. EnableWindow( GetDlgItem( dialog, IDC_BUTTON_BROWSE_PATH ), (current_drive->letter != 'C') );
  374. EnableWindow( GetDlgItem( dialog, IDC_COMBO_TYPE ), (current_drive->letter != 'C') );
  375. /* removable media properties */
  376. set_textW(dialog, IDC_EDIT_LABEL, current_drive->label ? current_drive->label : emptyW);
  377. /* set serial edit text */
  378. sprintf( serial, "%X", current_drive->serial );
  379. set_text(dialog, IDC_EDIT_SERIAL, serial);
  380. set_text(dialog, IDC_EDIT_DEVICE, current_drive->device);
  381. if ((type == DRIVE_CDROM) || (type == DRIVE_REMOVABLE))
  382. enable_labelserial_box(dialog, BOX_MODE_DEVICE);
  383. else
  384. enable_labelserial_box(dialog, BOX_MODE_NORMAL);
  385. updating_ui = FALSE;
  386. return;
  387. }
  388. static void on_edit_changed(HWND dialog, WORD id)
  389. {
  390. if (updating_ui) return;
  391. WINE_TRACE("edit id %d changed\n", id);
  392. switch (id)
  393. {
  394. case IDC_EDIT_LABEL:
  395. {
  396. WCHAR *label = get_textW(dialog, id);
  397. HeapFree(GetProcessHeap(), 0, current_drive->label);
  398. current_drive->label = label;
  399. current_drive->modified = TRUE;
  400. WINE_TRACE("set label to %s\n", wine_dbgstr_w(current_drive->label));
  401. /* enable the apply button */
  402. SendMessageW(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
  403. break;
  404. }
  405. case IDC_EDIT_PATH:
  406. {
  407. WCHAR *wpath;
  408. char *path;
  409. int lenW;
  410. wpath = get_textW(dialog, id);
  411. if( (lenW = WideCharToMultiByte(CP_UNIXCP, 0, wpath, -1, NULL, 0, NULL, NULL)) )
  412. {
  413. path = HeapAlloc(GetProcessHeap(), 0, lenW);
  414. WideCharToMultiByte(CP_UNIXCP, 0, wpath, -1, path, lenW, NULL, NULL);
  415. }
  416. else
  417. {
  418. path = NULL;
  419. wpath = strdupU2W("drive_c");
  420. }
  421. HeapFree(GetProcessHeap(), 0, current_drive->unixpath);
  422. current_drive->unixpath = path ? path : strdupA("drive_c");
  423. current_drive->modified = TRUE;
  424. WINE_TRACE("set path to %s\n", current_drive->unixpath);
  425. lv_set_item_text(dialog, lv_get_curr_select(dialog), 1,
  426. wpath);
  427. HeapFree(GetProcessHeap(), 0, wpath);
  428. /* enable the apply button */
  429. SendMessageW(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
  430. break;
  431. }
  432. case IDC_EDIT_SERIAL:
  433. {
  434. char *serial;
  435. serial = get_text(dialog, id);
  436. current_drive->serial = serial ? strtoul( serial, NULL, 16 ) : 0;
  437. HeapFree(GetProcessHeap(), 0, serial);
  438. current_drive->modified = TRUE;
  439. WINE_TRACE("set serial to %08X\n", current_drive->serial);
  440. /* enable the apply button */
  441. SendMessageW(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
  442. break;
  443. }
  444. case IDC_EDIT_DEVICE:
  445. {
  446. char *device = get_text(dialog, id);
  447. /* TODO: handle device if/when it makes sense to do so.... */
  448. HeapFree(GetProcessHeap(), 0, device);
  449. break;
  450. }
  451. }
  452. }
  453. BOOL browse_for_unix_folder(HWND dialog, WCHAR *pszPath)
  454. {
  455. static WCHAR wszUnixRootDisplayName[] =
  456. { ':',':','{','C','C','7','0','2','E','B','2','-','7','D','C','5','-','1','1','D','9','-',
  457. 'C','6','8','7','-','0','0','0','4','2','3','8','A','0','1','C','D','}', 0 };
  458. WCHAR pszChoosePath[FILENAME_MAX];
  459. BROWSEINFOW bi = {
  460. dialog,
  461. NULL,
  462. NULL,
  463. pszChoosePath,
  464. 0,
  465. NULL,
  466. 0,
  467. 0
  468. };
  469. IShellFolder *pDesktop;
  470. LPITEMIDLIST pidlUnixRoot, pidlSelectedPath;
  471. HRESULT hr;
  472. LoadStringW(GetModuleHandleW(NULL), IDS_CHOOSE_PATH, pszChoosePath, FILENAME_MAX);
  473. hr = SHGetDesktopFolder(&pDesktop);
  474. if (FAILED(hr)) return FALSE;
  475. hr = IShellFolder_ParseDisplayName(pDesktop, NULL, NULL, wszUnixRootDisplayName, NULL,
  476. &pidlUnixRoot, NULL);
  477. if (FAILED(hr)) {
  478. IShellFolder_Release(pDesktop);
  479. return FALSE;
  480. }
  481. bi.pidlRoot = pidlUnixRoot;
  482. pidlSelectedPath = SHBrowseForFolderW(&bi);
  483. SHFree(pidlUnixRoot);
  484. if (pidlSelectedPath) {
  485. STRRET strSelectedPath;
  486. WCHAR *pszSelectedPath;
  487. HRESULT hr;
  488. hr = IShellFolder_GetDisplayNameOf(pDesktop, pidlSelectedPath, SHGDN_FORPARSING,
  489. &strSelectedPath);
  490. IShellFolder_Release(pDesktop);
  491. if (FAILED(hr)) {
  492. SHFree(pidlSelectedPath);
  493. return FALSE;
  494. }
  495. hr = StrRetToStrW(&strSelectedPath, pidlSelectedPath, &pszSelectedPath);
  496. SHFree(pidlSelectedPath);
  497. if (FAILED(hr)) return FALSE;
  498. lstrcpyW(pszPath, pszSelectedPath);
  499. CoTaskMemFree(pszSelectedPath);
  500. return TRUE;
  501. }
  502. return FALSE;
  503. }
  504. static void init_listview_columns(HWND dialog)
  505. {
  506. LVCOLUMNW listColumn;
  507. RECT viewRect;
  508. int width;
  509. WCHAR column[64];
  510. GetClientRect(GetDlgItem(dialog, IDC_LIST_DRIVES), &viewRect);
  511. width = (viewRect.right - viewRect.left) / 6 - 5;
  512. LoadStringW(GetModuleHandleW(NULL), IDS_COL_DRIVELETTER, column, ARRAY_SIZE(column));
  513. listColumn.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
  514. listColumn.pszText = column;
  515. listColumn.cchTextMax = lstrlenW (listColumn.pszText);
  516. listColumn.cx = width;
  517. SendDlgItemMessageW (dialog, IDC_LIST_DRIVES, LVM_INSERTCOLUMNW, 0, (LPARAM) &listColumn);
  518. LoadStringW(GetModuleHandleW(NULL), IDS_COL_DRIVEMAPPING, column, ARRAY_SIZE(column));
  519. listColumn.cx = viewRect.right - viewRect.left - width;
  520. listColumn.pszText = column;
  521. listColumn.cchTextMax = lstrlenW (listColumn.pszText);
  522. SendDlgItemMessageW (dialog, IDC_LIST_DRIVES, LVM_INSERTCOLUMNW, 1, (LPARAM) &listColumn);
  523. }
  524. static void load_drive_options(HWND dialog)
  525. {
  526. if (!strcmp(get_reg_key(config_key, "", "ShowDotFiles", "N"), "Y"))
  527. CheckDlgButton(dialog, IDC_SHOW_DOT_FILES, BST_CHECKED);
  528. }
  529. INT_PTR CALLBACK
  530. DriveDlgProc (HWND dialog, UINT msg, WPARAM wParam, LPARAM lParam)
  531. {
  532. int item;
  533. switch (msg)
  534. {
  535. case WM_INITDIALOG:
  536. init_listview_columns(dialog);
  537. if (!load_drives())
  538. {
  539. ShowWindow( GetDlgItem( dialog, IDC_STATIC_MOUNTMGR_ERROR ), SW_SHOW );
  540. ShowWindow( GetDlgItem( dialog, IDC_LIST_DRIVES ), SW_HIDE );
  541. ShowWindow( GetDlgItem( dialog, IDC_BUTTON_ADD ), SW_HIDE );
  542. ShowWindow( GetDlgItem( dialog, IDC_BUTTON_REMOVE ), SW_HIDE );
  543. ShowWindow( GetDlgItem( dialog, IDC_STATIC_PATH ), SW_HIDE );
  544. ShowWindow( GetDlgItem( dialog, IDC_EDIT_PATH ), SW_HIDE );
  545. ShowWindow( GetDlgItem( dialog, IDC_BUTTON_BROWSE_PATH ), SW_HIDE );
  546. ShowWindow( GetDlgItem( dialog, IDC_COMBO_TYPE ), SW_HIDE );
  547. ShowWindow( GetDlgItem( dialog, IDC_BUTTON_SHOW_HIDE_ADVANCED ), SW_HIDE );
  548. set_advanced(dialog);
  549. break;
  550. }
  551. ShowWindow( GetDlgItem( dialog, IDC_STATIC_MOUNTMGR_ERROR ), SW_HIDE );
  552. load_drive_options(dialog);
  553. if (!drives[2].in_use)
  554. driveui_msgbox (dialog, IDS_NO_DRIVE_C, MB_OK | MB_ICONEXCLAMATION);
  555. fill_drives_list(dialog);
  556. update_controls(dialog);
  557. /* put in non-advanced mode by default */
  558. set_advanced(dialog);
  559. break;
  560. case WM_SHOWWINDOW:
  561. set_window_title(dialog);
  562. break;
  563. case WM_COMMAND:
  564. switch (HIWORD(wParam))
  565. {
  566. case EN_CHANGE:
  567. on_edit_changed(dialog, LOWORD(wParam));
  568. break;
  569. case BN_CLICKED:
  570. switch (LOWORD(wParam))
  571. {
  572. case IDC_SHOW_DOT_FILES:
  573. on_options_click(dialog);
  574. break;
  575. }
  576. break;
  577. case CBN_SELCHANGE:
  578. SendMessageW(GetParent(dialog), PSM_CHANGED, 0, 0);
  579. break;
  580. }
  581. switch (LOWORD(wParam))
  582. {
  583. case IDC_BUTTON_ADD:
  584. if (HIWORD(wParam) != BN_CLICKED) break;
  585. on_add_click(dialog);
  586. break;
  587. case IDC_BUTTON_REMOVE:
  588. if (HIWORD(wParam) != BN_CLICKED) break;
  589. on_remove_click(dialog);
  590. break;
  591. case IDC_BUTTON_EDIT:
  592. if (HIWORD(wParam) != BN_CLICKED) break;
  593. item = SendMessageW(GetDlgItem(dialog, IDC_LIST_DRIVES), LB_GETCURSEL, 0, 0);
  594. SendMessageW(GetDlgItem(dialog, IDC_LIST_DRIVES), LB_GETITEMDATA, item, 0);
  595. break;
  596. case IDC_BUTTON_SHOW_HIDE_ADVANCED:
  597. advanced = !advanced;
  598. set_advanced(dialog);
  599. break;
  600. case IDC_BUTTON_BROWSE_PATH:
  601. {
  602. WCHAR szTargetPath[FILENAME_MAX];
  603. if (browse_for_unix_folder(dialog, szTargetPath))
  604. set_textW(dialog, IDC_EDIT_PATH, szTargetPath);
  605. break;
  606. }
  607. case IDC_COMBO_TYPE:
  608. {
  609. int mode = BOX_MODE_NORMAL;
  610. int selection;
  611. if (HIWORD(wParam) != CBN_SELCHANGE) break;
  612. selection = SendDlgItemMessageW(dialog, IDC_COMBO_TYPE, CB_GETCURSEL, 0, 0);
  613. if (selection >= 0 &&
  614. (type_pairs[selection].sCode == DRIVE_CDROM ||
  615. type_pairs[selection].sCode == DRIVE_REMOVABLE))
  616. mode = BOX_MODE_DEVICE;
  617. else
  618. mode = BOX_MODE_NORMAL;
  619. enable_labelserial_box(dialog, mode);
  620. current_drive->type = type_pairs[selection].sCode;
  621. current_drive->modified = TRUE;
  622. break;
  623. }
  624. }
  625. break;
  626. case WM_NOTIFY:
  627. switch (((LPNMHDR)lParam)->code)
  628. {
  629. case PSN_KILLACTIVE:
  630. WINE_TRACE("PSN_KILLACTIVE\n");
  631. SetWindowLongPtrW(dialog, DWLP_MSGRESULT, FALSE);
  632. break;
  633. case PSN_APPLY:
  634. apply_drive_changes();
  635. SetWindowLongPtrW(dialog, DWLP_MSGRESULT, PSNRET_NOERROR);
  636. break;
  637. case PSN_SETACTIVE:
  638. break;
  639. case LVN_ITEMCHANGED:
  640. {
  641. LPNMLISTVIEW lpnm = (LPNMLISTVIEW)lParam;
  642. if (!(lpnm->uOldState & LVIS_SELECTED) &&
  643. (lpnm->uNewState & LVIS_SELECTED))
  644. update_controls(dialog);
  645. break;
  646. }
  647. }
  648. break;
  649. }
  650. return FALSE;
  651. }