maintainers: Update winemaker section.
[wine.git] / programs / winecfg / driveui.c
blob98e057bd7957e07c8915763e7d14c60b01b38aef
1 /*
2 * Drive management UI code
4 * Copyright 2003 Mark Westcott
5 * Copyright 2004 Chris Morgan
6 * Copyright 2003-2004 Mike Hearn
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.
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.
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
24 #include <stdio.h>
26 #define WIN32_LEAN_AND_MEAN
27 #define COBJMACROS
29 #include <windows.h>
30 #include <shellapi.h>
31 #include <objbase.h>
32 #include <shlguid.h>
33 #include <shlwapi.h>
34 #include <shlobj.h>
36 #include <wine/unicode.h>
37 #include <wine/debug.h>
39 #include "winecfg.h"
40 #include "resource.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
44 #define BOX_MODE_DEVICE 1
45 #define BOX_MODE_NORMAL 2
47 static BOOL advanced = FALSE;
48 static BOOL updating_ui = FALSE;
49 static struct drive* current_drive;
51 static void update_controls(HWND dialog);
53 static DWORD driveui_msgbox (HWND parent, UINT messageId, DWORD flags)
55 WCHAR* caption = load_string (IDS_WINECFG_TITLE);
56 WCHAR* text = load_string (messageId);
57 DWORD result = MessageBoxW (parent, text, caption, flags);
58 HeapFree (GetProcessHeap(), 0, caption);
59 HeapFree (GetProcessHeap(), 0, text);
60 return result;
63 /**** listview helper functions ****/
65 /* clears the item at index in the listview */
66 static void lv_clear_curr_select(HWND dialog, int index)
68 LVITEMW item;
70 item.mask = LVIF_STATE;
71 item.state = 0;
72 item.stateMask = LVIS_SELECTED;
73 SendDlgItemMessageW( dialog, IDC_LIST_DRIVES, LVM_SETITEMSTATE, index, (LPARAM)&item );
76 /* selects the item at index in the listview */
77 static void lv_set_curr_select(HWND dialog, int index)
79 LVITEMW item;
81 /* no more than one item can be selected in our listview */
82 lv_clear_curr_select(dialog, -1);
83 item.mask = LVIF_STATE;
84 item.state = LVIS_SELECTED;
85 item.stateMask = LVIS_SELECTED;
86 SendDlgItemMessageW( dialog, IDC_LIST_DRIVES, LVM_SETITEMSTATE, index, (LPARAM)&item );
89 /* returns the currently selected item in the listview */
90 static int lv_get_curr_select(HWND dialog)
92 return SendDlgItemMessageW(dialog, IDC_LIST_DRIVES, LVM_GETNEXTITEM, -1, LVNI_SELECTED);
95 /* sets the item in the listview at item->iIndex */
96 static void lv_set_item(HWND dialog, LVITEMW *item)
98 SendDlgItemMessageW(dialog, IDC_LIST_DRIVES, LVM_SETITEMW, 0, (LPARAM) item);
101 /* sets specified item's text */
102 static void lv_set_item_text(HWND dialog, int item, int subItem, WCHAR *text)
104 LVITEMW lvItem;
105 if (item < 0 || subItem < 0) return;
106 lvItem.mask = LVIF_TEXT;
107 lvItem.iItem = item;
108 lvItem.iSubItem = subItem;
109 lvItem.pszText = text;
110 lvItem.cchTextMax = lstrlenW(lvItem.pszText);
111 lv_set_item(dialog, &lvItem);
114 /* inserts an item into the listview */
115 static void lv_insert_item(HWND dialog, LVITEMW *item)
117 SendDlgItemMessageW(dialog, IDC_LIST_DRIVES, LVM_INSERTITEMW, 0, (LPARAM) item);
120 /* retrieve the item at index item->iIndex */
121 static void lv_get_item(HWND dialog, LVITEMW *item)
123 SendDlgItemMessageW(dialog, IDC_LIST_DRIVES, LVM_GETITEMW, 0, (LPARAM) item);
126 static void set_advanced(HWND dialog)
128 int state;
129 WCHAR text[256];
131 if (advanced)
133 state = SW_NORMAL;
134 LoadStringW(GetModuleHandleW(NULL), IDS_HIDE_ADVANCED, text, 256);
136 else
138 state = SW_HIDE;
139 LoadStringW(GetModuleHandleW(NULL), IDS_SHOW_ADVANCED, text, 256);
142 ShowWindow(GetDlgItem(dialog, IDC_EDIT_DEVICE), state);
143 ShowWindow(GetDlgItem(dialog, IDC_STATIC_DEVICE), state);
144 ShowWindow(GetDlgItem(dialog, IDC_EDIT_LABEL), state);
145 ShowWindow(GetDlgItem(dialog, IDC_STATIC_LABEL), state);
146 ShowWindow(GetDlgItem(dialog, IDC_BUTTON_BROWSE_DEVICE), state);
147 ShowWindow(GetDlgItem(dialog, IDC_EDIT_SERIAL), state);
148 ShowWindow(GetDlgItem(dialog, IDC_STATIC_SERIAL), state);
149 ShowWindow(GetDlgItem(dialog, IDC_COMBO_TYPE), state);
150 ShowWindow(GetDlgItem(dialog, IDC_STATIC_TYPE), state);
152 /* update the button text based on the state */
153 SetWindowTextW(GetDlgItem(dialog, IDC_BUTTON_SHOW_HIDE_ADVANCED), text);
156 struct drive_typemap {
157 unsigned int sCode;
158 UINT idDesc;
161 static const struct drive_typemap type_pairs[] = {
162 { DRIVE_UNKNOWN, IDS_DRIVE_UNKNOWN },
163 { DRIVE_FIXED, IDS_DRIVE_FIXED },
164 { DRIVE_REMOTE, IDS_DRIVE_REMOTE },
165 { DRIVE_REMOVABLE, IDS_DRIVE_REMOVABLE },
166 { DRIVE_CDROM, IDS_DRIVE_CDROM }
169 #define DRIVE_TYPE_DEFAULT 0
171 static void enable_labelserial_box(HWND dialog, int mode)
173 WINE_TRACE("mode=%d\n", mode);
175 switch (mode)
177 case BOX_MODE_DEVICE:
178 /* FIXME: enable device editing */
179 disable(IDC_EDIT_DEVICE);
180 disable(IDC_BUTTON_BROWSE_DEVICE);
181 disable(IDC_EDIT_SERIAL);
182 disable(IDC_EDIT_LABEL);
183 break;
185 case BOX_MODE_NORMAL:
186 disable(IDC_EDIT_DEVICE);
187 disable(IDC_BUTTON_BROWSE_DEVICE);
188 enable(IDC_EDIT_SERIAL);
189 enable(IDC_EDIT_LABEL);
190 break;
194 static int fill_drives_list(HWND dialog)
196 int count = 0;
197 BOOL drivec_present = FALSE;
198 int i;
199 int prevsel = -1;
201 WINE_TRACE("\n");
203 updating_ui = TRUE;
205 prevsel = lv_get_curr_select(dialog);
207 /* Clear the listbox */
208 SendDlgItemMessageW(dialog, IDC_LIST_DRIVES, LVM_DELETEALLITEMS, 0, 0);
210 for(i = 0; i < 26; i++)
212 LVITEMW item;
213 WCHAR *path;
214 char letter[4];
216 /* skip over any unused drives */
217 if (!drives[i].in_use)
218 continue;
220 if (drives[i].letter == 'C')
221 drivec_present = TRUE;
223 letter[0] = 'A' + i;
224 letter[1] = ':';
225 letter[2] = 0;
227 item.mask = LVIF_TEXT | LVIF_PARAM;
228 item.iItem = count;
229 item.iSubItem = 0;
230 item.pszText = strdupU2W(letter);
231 item.cchTextMax = lstrlenW(item.pszText);
232 item.lParam = (LPARAM) &drives[i];
234 lv_insert_item(dialog, &item);
235 HeapFree(GetProcessHeap(), 0, item.pszText);
237 path = strdupU2W(drives[i].unixpath);
238 lv_set_item_text(dialog, count, 1, path);
239 HeapFree(GetProcessHeap(), 0, path);
241 count++;
244 WINE_TRACE("loaded %d drives\n", count);
246 /* show the warning if there is no Drive C */
247 if (!drivec_present)
248 ShowWindow(GetDlgItem(dialog, IDS_DRIVE_NO_C), SW_NORMAL);
249 else
250 ShowWindow(GetDlgItem(dialog, IDS_DRIVE_NO_C), SW_HIDE);
252 lv_set_curr_select(dialog, prevsel == -1 ? 0 : prevsel);
254 updating_ui = FALSE;
255 return count;
258 static void on_options_click(HWND dialog)
260 if (IsDlgButtonChecked(dialog, IDC_SHOW_DOT_FILES) == BST_CHECKED)
261 set_reg_key(config_key, "", "ShowDotFiles", "Y");
262 else
263 set_reg_key(config_key, "", "ShowDotFiles", "N");
265 SendMessageW(GetParent(dialog), PSM_CHANGED, 0, 0);
268 static INT_PTR CALLBACK drivechoose_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
270 static int i, sel;
271 char c;
272 char drive[] = "X:";
274 switch(uMsg)
276 case WM_INITDIALOG:
278 ULONG mask = ~drive_available_mask(0); /* the mask is now which drives aren't available */
279 for( c = 'A'; c<= 'Z'; c++){
280 drive[0] = c;
281 if(!( mask & (1 << (c - 'A'))))
282 SendDlgItemMessageA( hwndDlg, IDC_DRIVESA2Z, CB_ADDSTRING, 0, (LPARAM) drive);
284 drive[0] = lParam;
285 SendDlgItemMessageA( hwndDlg, IDC_DRIVESA2Z, CB_SELECTSTRING, 0, (LPARAM) drive);
286 return TRUE;
288 case WM_COMMAND:
289 if(HIWORD(wParam) != BN_CLICKED) break;
290 switch (LOWORD(wParam))
292 case IDOK:
293 i = SendDlgItemMessageA( hwndDlg, IDC_DRIVESA2Z, CB_GETCURSEL, 0, 0);
294 if( i != CB_ERR){
295 SendDlgItemMessageA( hwndDlg, IDC_DRIVESA2Z, CB_GETLBTEXT, i, (LPARAM) drive);
296 sel = drive[0];
297 } else
298 sel = -1;
299 EndDialog(hwndDlg, sel);
300 return TRUE;
301 case IDCANCEL:
302 EndDialog(hwndDlg, -1);
303 return TRUE;
306 return FALSE;
309 static void on_add_click(HWND dialog)
311 /* we should allocate a drive letter automatically. We also need
312 some way to let the user choose the mapping point, for now we
313 will just force them to enter a path automatically, with / being
314 the default. In future we should be able to temporarily map /
315 then invoke the directory chooser dialog. */
317 char new = 'C'; /* we skip A and B, they are historically floppy drives */
318 ULONG mask = ~drive_available_mask(0); /* the mask is now which drives aren't available */
319 int i, c;
320 INT_PTR ret;
322 while (mask & (1 << (new - 'A')))
324 new++;
325 if (new > 'Z')
327 driveui_msgbox (dialog, IDS_DRIVE_LETTERS_EXCEEDED, MB_OK | MB_ICONEXCLAMATION);
328 return;
333 ret = DialogBoxParamW(0, MAKEINTRESOURCEW(IDD_DRIVECHOOSE), dialog, drivechoose_dlgproc, new);
335 if( ret == -1) return;
336 new = ret;
338 WINE_TRACE("selected drive letter %c\n", new);
340 if (new == 'C')
342 WCHAR label[64];
343 LoadStringW (GetModuleHandleW(NULL), IDS_SYSTEM_DRIVE_LABEL, label,
344 sizeof(label)/sizeof(label[0]));
345 add_drive(new, "../drive_c", NULL, label, 0, DRIVE_FIXED);
347 else add_drive(new, "/", NULL, NULL, 0, DRIVE_UNKNOWN);
349 fill_drives_list(dialog);
351 /* select the newly created drive */
352 mask = ~drive_available_mask(0);
353 c = 0;
354 for (i = 0; i < 26; i++)
356 if ('A' + i == new) break;
357 if ((1 << i) & mask) c++;
359 lv_set_curr_select(dialog, c);
361 SetFocus(GetDlgItem(dialog, IDC_LIST_DRIVES));
363 update_controls(dialog);
364 SendMessageW(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
367 static void on_remove_click(HWND dialog)
369 int itemIndex;
370 struct drive *drive;
371 LVITEMW item;
373 itemIndex = lv_get_curr_select(dialog);
374 if (itemIndex == -1) return; /* no selection */
376 item.mask = LVIF_PARAM;
377 item.iItem = itemIndex;
378 item.iSubItem = 0;
380 lv_get_item(dialog, &item);
382 drive = (struct drive *) item.lParam;
384 WINE_TRACE("unixpath: %s\n", drive->unixpath);
386 if (drive->letter == 'C')
388 DWORD result = driveui_msgbox (dialog, IDS_CONFIRM_DELETE_C, MB_YESNO | MB_ICONEXCLAMATION);
389 if (result == IDNO) return;
392 delete_drive(drive);
394 fill_drives_list(dialog);
396 itemIndex = itemIndex - 1;
397 if (itemIndex < 0) itemIndex = 0;
398 lv_set_curr_select(dialog, itemIndex); /* previous item */
400 SetFocus(GetDlgItem(dialog, IDC_LIST_DRIVES));
402 update_controls(dialog);
403 SendMessageW(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
406 static void update_controls(HWND dialog)
408 static const WCHAR emptyW[1];
409 WCHAR *path;
410 unsigned int type;
411 char serial[16];
412 int i, selection = -1;
413 LVITEMW item;
415 updating_ui = TRUE;
417 i = lv_get_curr_select(dialog);
418 if (i == -1)
420 /* no selection? let's select something for the user. this will re-enter */
421 lv_set_curr_select(dialog, i);
422 return;
425 item.mask = LVIF_PARAM;
426 item.iItem = i;
427 item.iSubItem = 0;
429 lv_get_item(dialog, &item);
430 current_drive = (struct drive *) item.lParam;
432 WINE_TRACE("Updating sheet for drive %c\n", current_drive->letter);
434 /* path */
435 WINE_TRACE("set path control text to '%s'\n", current_drive->unixpath);
436 path = strdupU2W(current_drive->unixpath);
437 set_textW(dialog, IDC_EDIT_PATH, path);
438 HeapFree(GetProcessHeap(), 0, path);
440 /* drive type */
441 type = current_drive->type;
442 SendDlgItemMessageW(dialog, IDC_COMBO_TYPE, CB_RESETCONTENT, 0, 0);
444 for (i = 0; i < sizeof(type_pairs) / sizeof(struct drive_typemap); i++)
446 WCHAR driveDesc[64];
447 LoadStringW (GetModuleHandleW(NULL), type_pairs[i].idDesc, driveDesc,
448 sizeof(driveDesc)/sizeof(driveDesc[0]));
449 SendDlgItemMessageW (dialog, IDC_COMBO_TYPE, CB_ADDSTRING, 0, (LPARAM)driveDesc);
451 if (type_pairs[i].sCode == type)
453 selection = i;
457 if (selection == -1) selection = DRIVE_TYPE_DEFAULT;
458 SendDlgItemMessageW(dialog, IDC_COMBO_TYPE, CB_SETCURSEL, selection, 0);
460 EnableWindow( GetDlgItem( dialog, IDC_BUTTON_REMOVE ), (current_drive->letter != 'C') );
461 EnableWindow( GetDlgItem( dialog, IDC_EDIT_PATH ), (current_drive->letter != 'C') );
462 EnableWindow( GetDlgItem( dialog, IDC_BUTTON_BROWSE_PATH ), (current_drive->letter != 'C') );
463 EnableWindow( GetDlgItem( dialog, IDC_COMBO_TYPE ), (current_drive->letter != 'C') );
465 /* removable media properties */
466 set_textW(dialog, IDC_EDIT_LABEL, current_drive->label ? current_drive->label : emptyW);
468 /* set serial edit text */
469 sprintf( serial, "%X", current_drive->serial );
470 set_text(dialog, IDC_EDIT_SERIAL, serial);
472 set_text(dialog, IDC_EDIT_DEVICE, current_drive->device);
474 if ((type == DRIVE_CDROM) || (type == DRIVE_REMOVABLE))
475 enable_labelserial_box(dialog, BOX_MODE_DEVICE);
476 else
477 enable_labelserial_box(dialog, BOX_MODE_NORMAL);
479 updating_ui = FALSE;
481 return;
484 static void on_edit_changed(HWND dialog, WORD id)
486 if (updating_ui) return;
488 WINE_TRACE("edit id %d changed\n", id);
490 switch (id)
492 case IDC_EDIT_LABEL:
494 WCHAR *label = get_textW(dialog, id);
495 HeapFree(GetProcessHeap(), 0, current_drive->label);
496 current_drive->label = label;
497 current_drive->modified = TRUE;
499 WINE_TRACE("set label to %s\n", wine_dbgstr_w(current_drive->label));
501 /* enable the apply button */
502 SendMessageW(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
503 break;
506 case IDC_EDIT_PATH:
508 WCHAR *wpath;
509 char *path;
510 int lenW;
512 wpath = get_textW(dialog, id);
513 if( (lenW = WideCharToMultiByte(CP_UNIXCP, 0, wpath, -1, NULL, 0, NULL, NULL)) )
515 path = HeapAlloc(GetProcessHeap(), 0, lenW);
516 WideCharToMultiByte(CP_UNIXCP, 0, wpath, -1, path, lenW, NULL, NULL);
518 else
520 path = NULL;
521 wpath = strdupU2W("drive_c");
524 HeapFree(GetProcessHeap(), 0, current_drive->unixpath);
525 current_drive->unixpath = path ? path : strdupA("drive_c");
526 current_drive->modified = TRUE;
528 WINE_TRACE("set path to %s\n", current_drive->unixpath);
530 lv_set_item_text(dialog, lv_get_curr_select(dialog), 1,
531 wpath);
532 HeapFree(GetProcessHeap(), 0, wpath);
534 /* enable the apply button */
535 SendMessageW(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
536 break;
539 case IDC_EDIT_SERIAL:
541 char *serial;
543 serial = get_text(dialog, id);
544 current_drive->serial = serial ? strtoul( serial, NULL, 16 ) : 0;
545 HeapFree(GetProcessHeap(), 0, serial);
546 current_drive->modified = TRUE;
548 WINE_TRACE("set serial to %08X\n", current_drive->serial);
550 /* enable the apply button */
551 SendMessageW(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
552 break;
555 case IDC_EDIT_DEVICE:
557 char *device = get_text(dialog, id);
558 /* TODO: handle device if/when it makes sense to do so.... */
559 HeapFree(GetProcessHeap(), 0, device);
560 break;
565 BOOL browse_for_unix_folder(HWND dialog, WCHAR *pszPath)
567 static WCHAR wszUnixRootDisplayName[] =
568 { ':',':','{','C','C','7','0','2','E','B','2','-','7','D','C','5','-','1','1','D','9','-',
569 'C','6','8','7','-','0','0','0','4','2','3','8','A','0','1','C','D','}', 0 };
570 WCHAR pszChoosePath[FILENAME_MAX];
571 BROWSEINFOW bi = {
572 dialog,
573 NULL,
574 NULL,
575 pszChoosePath,
577 NULL,
581 IShellFolder *pDesktop;
582 LPITEMIDLIST pidlUnixRoot, pidlSelectedPath;
583 HRESULT hr;
585 LoadStringW(GetModuleHandleW(NULL), IDS_CHOOSE_PATH, pszChoosePath, FILENAME_MAX);
587 hr = SHGetDesktopFolder(&pDesktop);
588 if (FAILED(hr)) return FALSE;
590 hr = IShellFolder_ParseDisplayName(pDesktop, NULL, NULL, wszUnixRootDisplayName, NULL,
591 &pidlUnixRoot, NULL);
592 if (FAILED(hr)) {
593 IShellFolder_Release(pDesktop);
594 return FALSE;
597 bi.pidlRoot = pidlUnixRoot;
598 pidlSelectedPath = SHBrowseForFolderW(&bi);
599 SHFree(pidlUnixRoot);
601 if (pidlSelectedPath) {
602 STRRET strSelectedPath;
603 WCHAR *pszSelectedPath;
604 HRESULT hr;
606 hr = IShellFolder_GetDisplayNameOf(pDesktop, pidlSelectedPath, SHGDN_FORPARSING,
607 &strSelectedPath);
608 IShellFolder_Release(pDesktop);
609 if (FAILED(hr)) {
610 SHFree(pidlSelectedPath);
611 return FALSE;
614 hr = StrRetToStrW(&strSelectedPath, pidlSelectedPath, &pszSelectedPath);
615 SHFree(pidlSelectedPath);
616 if (FAILED(hr)) return FALSE;
618 lstrcpyW(pszPath, pszSelectedPath);
620 CoTaskMemFree(pszSelectedPath);
621 return TRUE;
623 return FALSE;
626 static void init_listview_columns(HWND dialog)
628 LVCOLUMNW listColumn;
629 RECT viewRect;
630 int width;
631 WCHAR column[64];
633 GetClientRect(GetDlgItem(dialog, IDC_LIST_DRIVES), &viewRect);
634 width = (viewRect.right - viewRect.left) / 6 - 5;
636 LoadStringW (GetModuleHandleW(NULL), IDS_COL_DRIVELETTER, column,
637 sizeof(column)/sizeof(column[0]));
638 listColumn.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
639 listColumn.pszText = column;
640 listColumn.cchTextMax = lstrlenW (listColumn.pszText);
641 listColumn.cx = width;
643 SendDlgItemMessageW (dialog, IDC_LIST_DRIVES, LVM_INSERTCOLUMNW, 0, (LPARAM) &listColumn);
645 LoadStringW (GetModuleHandleW(NULL), IDS_COL_DRIVEMAPPING, column,
646 sizeof(column)/sizeof(column[0]));
647 listColumn.cx = viewRect.right - viewRect.left - width;
648 listColumn.pszText = column;
649 listColumn.cchTextMax = lstrlenW (listColumn.pszText);
651 SendDlgItemMessageW (dialog, IDC_LIST_DRIVES, LVM_INSERTCOLUMNW, 1, (LPARAM) &listColumn);
654 static void load_drive_options(HWND dialog)
656 if (!strcmp(get_reg_key(config_key, "", "ShowDotFiles", "N"), "Y"))
657 CheckDlgButton(dialog, IDC_SHOW_DOT_FILES, BST_CHECKED);
660 INT_PTR CALLBACK
661 DriveDlgProc (HWND dialog, UINT msg, WPARAM wParam, LPARAM lParam)
663 int item;
665 switch (msg)
667 case WM_INITDIALOG:
668 init_listview_columns(dialog);
669 if (!load_drives())
671 ShowWindow( GetDlgItem( dialog, IDC_STATIC_MOUNTMGR_ERROR ), SW_SHOW );
672 ShowWindow( GetDlgItem( dialog, IDC_LIST_DRIVES ), SW_HIDE );
673 ShowWindow( GetDlgItem( dialog, IDC_BUTTON_ADD ), SW_HIDE );
674 ShowWindow( GetDlgItem( dialog, IDC_BUTTON_REMOVE ), SW_HIDE );
675 ShowWindow( GetDlgItem( dialog, IDC_BUTTON_AUTODETECT ), SW_HIDE );
676 ShowWindow( GetDlgItem( dialog, IDC_STATIC_PATH ), SW_HIDE );
677 ShowWindow( GetDlgItem( dialog, IDC_EDIT_PATH ), SW_HIDE );
678 ShowWindow( GetDlgItem( dialog, IDC_BUTTON_BROWSE_PATH ), SW_HIDE );
679 ShowWindow( GetDlgItem( dialog, IDC_COMBO_TYPE ), SW_HIDE );
680 ShowWindow( GetDlgItem( dialog, IDC_BUTTON_SHOW_HIDE_ADVANCED ), SW_HIDE );
681 set_advanced(dialog);
682 break;
684 ShowWindow( GetDlgItem( dialog, IDC_STATIC_MOUNTMGR_ERROR ), SW_HIDE );
685 load_drive_options(dialog);
687 if (!drives[2].in_use)
688 driveui_msgbox (dialog, IDS_NO_DRIVE_C, MB_OK | MB_ICONEXCLAMATION);
690 fill_drives_list(dialog);
691 update_controls(dialog);
692 /* put in non-advanced mode by default */
693 set_advanced(dialog);
694 break;
696 case WM_SHOWWINDOW:
697 set_window_title(dialog);
698 break;
700 case WM_COMMAND:
701 switch (HIWORD(wParam))
703 case EN_CHANGE:
704 on_edit_changed(dialog, LOWORD(wParam));
705 break;
707 case BN_CLICKED:
708 switch (LOWORD(wParam))
710 case IDC_SHOW_DOT_FILES:
711 on_options_click(dialog);
712 break;
714 break;
716 case CBN_SELCHANGE:
717 SendMessageW(GetParent(dialog), PSM_CHANGED, 0, 0);
718 break;
721 switch (LOWORD(wParam))
723 case IDC_BUTTON_ADD:
724 if (HIWORD(wParam) != BN_CLICKED) break;
725 on_add_click(dialog);
726 break;
728 case IDC_BUTTON_REMOVE:
729 if (HIWORD(wParam) != BN_CLICKED) break;
730 on_remove_click(dialog);
731 break;
733 case IDC_BUTTON_EDIT:
734 if (HIWORD(wParam) != BN_CLICKED) break;
735 item = SendMessageW(GetDlgItem(dialog, IDC_LIST_DRIVES), LB_GETCURSEL, 0, 0);
736 SendMessageW(GetDlgItem(dialog, IDC_LIST_DRIVES), LB_GETITEMDATA, item, 0);
737 break;
739 case IDC_BUTTON_AUTODETECT:
740 autodetect_drives();
741 fill_drives_list(dialog);
742 SendMessageW(GetParent(dialog), PSM_CHANGED, 0, 0);
743 break;
745 case IDC_BUTTON_SHOW_HIDE_ADVANCED:
746 advanced = !advanced;
747 set_advanced(dialog);
748 break;
750 case IDC_BUTTON_BROWSE_PATH:
752 WCHAR szTargetPath[FILENAME_MAX];
753 if (browse_for_unix_folder(dialog, szTargetPath))
754 set_textW(dialog, IDC_EDIT_PATH, szTargetPath);
755 break;
758 case IDC_COMBO_TYPE:
760 int mode = BOX_MODE_NORMAL;
761 int selection;
763 if (HIWORD(wParam) != CBN_SELCHANGE) break;
765 selection = SendDlgItemMessageW(dialog, IDC_COMBO_TYPE, CB_GETCURSEL, 0, 0);
767 if (selection >= 0 &&
768 (type_pairs[selection].sCode == DRIVE_CDROM ||
769 type_pairs[selection].sCode == DRIVE_REMOVABLE))
770 mode = BOX_MODE_DEVICE;
771 else
772 mode = BOX_MODE_NORMAL;
774 enable_labelserial_box(dialog, mode);
776 current_drive->type = type_pairs[selection].sCode;
777 current_drive->modified = TRUE;
778 break;
782 break;
784 case WM_NOTIFY:
785 switch (((LPNMHDR)lParam)->code)
787 case PSN_KILLACTIVE:
788 WINE_TRACE("PSN_KILLACTIVE\n");
789 SetWindowLongPtrW(dialog, DWLP_MSGRESULT, FALSE);
790 break;
791 case PSN_APPLY:
792 apply_drive_changes();
793 SetWindowLongPtrW(dialog, DWLP_MSGRESULT, PSNRET_NOERROR);
794 break;
795 case PSN_SETACTIVE:
796 break;
797 case LVN_ITEMCHANGED:
799 LPNMLISTVIEW lpnm = (LPNMLISTVIEW)lParam;
800 if (!(lpnm->uOldState & LVIS_SELECTED) &&
801 (lpnm->uNewState & LVIS_SELECTED))
802 update_controls(dialog);
803 break;
806 break;
809 return FALSE;