msg711: Renamed the dlls/msacm/msg711 directory to dlls/msg711.acm.
[wine] / programs / winecfg / driveui.c
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  */
23
24 #include <stdio.h>
25
26 #define WIN32_LEAN_AND_MEAN
27 #define COBJMACROS
28
29 #include <windows.h>
30 #include <shellapi.h>
31 #include <objbase.h>
32 #include <shlguid.h>
33 #include <shlwapi.h>
34 #include <shlobj.h>
35
36 #include <wine/debug.h>
37
38 #include "winecfg.h"
39 #include "resource.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
42
43 #define BOX_MODE_CD_ASSIGN 1
44 #define BOX_MODE_CD_AUTODETECT 2
45 #define BOX_MODE_NONE 3
46 #define BOX_MODE_NORMAL 4
47
48 static BOOL advanced = FALSE;
49 static BOOL updating_ui = FALSE;
50 static struct drive* current_drive;
51
52 static void get_etched_rect(HWND dialog, RECT *rect);
53 static void update_controls(HWND dialog);
54
55 /**** listview helper functions ****/
56
57 /* clears the item at index in the listview */
58 static void lv_clear_curr_select(HWND dialog, int index)
59 {
60     ListView_SetItemState(GetDlgItem(dialog, IDC_LIST_DRIVES), index, 0, LVIS_SELECTED);
61 }
62
63 /* selects the item at index in the listview */
64 static void lv_set_curr_select(HWND dialog, int index)
65 {
66     /* no more than one item can be selected in our listview */
67     lv_clear_curr_select(dialog, -1);
68     ListView_SetItemState(GetDlgItem(dialog, IDC_LIST_DRIVES), index, LVIS_SELECTED, LVIS_SELECTED);
69 }
70
71 /* returns the currently selected item in the listview */
72 static int lv_get_curr_select(HWND dialog)
73 {
74     return SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LVM_GETNEXTITEM, -1, LVNI_SELECTED);
75 }
76
77 /* sets the item in the listview at item->iIndex */
78 static void lv_set_item(HWND dialog, LVITEM *item)
79 {
80     SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LVM_SETITEM, 0, (LPARAM) item);
81 }
82
83 /* sets specified item's text */
84 static void lv_set_item_text(HWND dialog, int item, int subItem, char *text)
85 {
86     LVITEM 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 = lstrlen(lvItem.pszText);
93     lv_set_item(dialog, &lvItem);
94 }
95
96 /* inserts an item into the listview */
97 static void lv_insert_item(HWND dialog, LVITEM *item)
98 {
99     SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LVM_INSERTITEM, 0, (LPARAM) item);
100 }
101
102 /* retrieve the item at index item->iIndex */
103 static void lv_get_item(HWND dialog, LVITEM *item)
104 {
105     SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LVM_GETITEM, 0, (LPARAM) item);
106 }
107
108 static void set_advanced(HWND dialog)
109 {
110     int state;
111     char text[256];
112     RECT rect;
113
114     if (advanced)
115     {
116         state = SW_NORMAL;
117         LoadString(GetModuleHandle(NULL), IDS_HIDE_ADVANCED, text, 256);
118     }
119     else
120     {
121         state = SW_HIDE;
122         LoadString(GetModuleHandle(NULL), IDS_SHOW_ADVANCED, text, 256);
123     }
124
125     ShowWindow(GetDlgItem(dialog, IDC_RADIO_AUTODETECT), state);
126     ShowWindow(GetDlgItem(dialog, IDC_RADIO_ASSIGN), state);
127     ShowWindow(GetDlgItem(dialog, IDC_EDIT_LABEL), state);
128     ShowWindow(GetDlgItem(dialog, IDC_EDIT_DEVICE), state);
129     ShowWindow(GetDlgItem(dialog, IDC_STATIC_LABEL), state);
130     ShowWindow(GetDlgItem(dialog, IDC_BUTTON_BROWSE_DEVICE), state);
131     ShowWindow(GetDlgItem(dialog, IDC_EDIT_SERIAL), state);
132     ShowWindow(GetDlgItem(dialog, IDC_STATIC_SERIAL), state);
133     ShowWindow(GetDlgItem(dialog, IDC_LABELSERIAL_STATIC), state);
134     ShowWindow(GetDlgItem(dialog, IDC_COMBO_TYPE), state);
135     ShowWindow(GetDlgItem(dialog, IDC_STATIC_TYPE), state);
136
137     /* update the button text based on the state */
138     SetWindowText(GetDlgItem(dialog, IDC_BUTTON_SHOW_HIDE_ADVANCED), text);
139
140     /* redraw for the etched line */
141     get_etched_rect(dialog, &rect);
142     InflateRect(&rect, 5, 5);
143     InvalidateRect(dialog, &rect, TRUE);
144 }
145
146 struct drive_typemap {
147     unsigned int sCode;
148     const char *sDesc;
149 };
150
151 static const struct drive_typemap type_pairs[] = {
152   { DRIVE_UNKNOWN,    "Autodetect"      },
153   { DRIVE_FIXED,      "Local hard disk" },
154   { DRIVE_REMOTE,     "Network share"   },
155   { DRIVE_REMOVABLE,  "Floppy disk"     },
156   { DRIVE_CDROM,      "CD-ROM"          }
157 };
158
159 #define DRIVE_TYPE_DEFAULT 0
160
161 static void fill_drive_droplist(long mask, char curletter, HWND dialog)
162 {
163     int i;
164     int selection;
165     int count;
166     int next_letter;
167     char sName[4];
168
169     strcpy(sName, "A:");
170     for (i = 0, count = 0, selection = -1, next_letter = -1; i <= 'Z'-'A'; ++i)
171     {
172         if (mask & DRIVE_MASK_BIT('A' + i))
173         {
174             int index;
175
176             sName[0] = 'A' + i;
177             index = SendDlgItemMessage(dialog, IDC_COMBO_LETTER, CB_ADDSTRING, 0, (LPARAM) sName);
178
179             if (toupper(curletter) == 'A' + i)
180             {
181                 selection = count;
182             }
183
184             if (i >= 2 && next_letter == -1)
185             {
186                 /* default drive is first one of C-Z */
187                 next_letter = count;
188             }
189
190             count++;
191         }
192     }
193
194     if (selection == -1)
195     {
196         selection = next_letter;
197     }
198
199     SendDlgItemMessage(dialog, IDC_COMBO_LETTER, CB_SETCURSEL, selection, 0);
200 }
201
202
203 static void enable_labelserial_box(HWND dialog, int mode)
204 {
205     WINE_TRACE("mode=%d\n", mode);
206
207     switch (mode)
208     {
209         case BOX_MODE_CD_ASSIGN:
210             enable(IDC_RADIO_ASSIGN);
211             disable(IDC_EDIT_DEVICE);
212             disable(IDC_BUTTON_BROWSE_DEVICE);
213             enable(IDC_EDIT_SERIAL);
214             enable(IDC_EDIT_LABEL);
215             enable(IDC_STATIC_SERIAL);
216             enable(IDC_STATIC_LABEL);
217             break;
218
219         case BOX_MODE_CD_AUTODETECT:
220             enable(IDC_RADIO_ASSIGN);
221             enable(IDC_EDIT_DEVICE);
222             enable(IDC_BUTTON_BROWSE_DEVICE);
223             disable(IDC_EDIT_SERIAL);
224             disable(IDC_EDIT_LABEL);
225             disable(IDC_STATIC_SERIAL);
226             disable(IDC_STATIC_LABEL);
227             break;
228
229         case BOX_MODE_NONE:
230             disable(IDC_RADIO_ASSIGN);
231             disable(IDC_EDIT_DEVICE);
232             disable(IDC_BUTTON_BROWSE_DEVICE);
233             disable(IDC_EDIT_SERIAL);
234             disable(IDC_EDIT_LABEL);
235             disable(IDC_STATIC_SERIAL);
236             disable(IDC_STATIC_LABEL);
237             break;
238
239         case BOX_MODE_NORMAL:
240             enable(IDC_RADIO_ASSIGN);
241             disable(IDC_EDIT_DEVICE);
242             disable(IDC_BUTTON_BROWSE_DEVICE);
243             enable(IDC_EDIT_SERIAL);
244             enable(IDC_EDIT_LABEL);
245             enable(IDC_STATIC_SERIAL);
246             enable(IDC_STATIC_LABEL);
247             break;
248     }
249 }
250
251 static int fill_drives_list(HWND dialog)
252 {
253     int count = 0;
254     BOOL drivec_present = FALSE;
255     int i;
256     int prevsel = -1;
257
258     WINE_TRACE("\n");
259
260     updating_ui = TRUE;
261
262     prevsel = lv_get_curr_select(dialog); 
263
264     /* Clear the listbox */
265     SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LVM_DELETEALLITEMS, 0, 0);
266
267     for(i = 0; i < 26; i++)
268     {
269         LVITEM item;
270         char letter[4];
271
272         /* skip over any unused drives */
273         if (!drives[i].in_use)
274             continue;
275
276         if (drives[i].letter == 'C')
277             drivec_present = TRUE;
278
279         letter[0] = 'A' + i;
280         letter[1] = ':';
281         letter[2] = 0;
282
283         memset(&item, 0, sizeof(item));
284         item.mask = LVIF_TEXT | LVIF_PARAM;
285         item.iItem = count;
286         item.iSubItem = 0;
287         item.pszText = letter;
288         item.cchTextMax = lstrlen(item.pszText);
289         item.lParam = (LPARAM) &drives[i];
290
291         lv_insert_item(dialog, &item);
292         lv_set_item_text(dialog, count, 1, drives[i].unixpath);
293
294         count++;
295     }
296
297     WINE_TRACE("loaded %d drives\n", count);
298
299     /* show the warning if there is no Drive C */
300     if (!drivec_present)
301         ShowWindow(GetDlgItem(dialog, IDS_DRIVE_NO_C), SW_NORMAL);
302     else
303         ShowWindow(GetDlgItem(dialog, IDS_DRIVE_NO_C), SW_HIDE);
304
305     lv_set_curr_select(dialog, prevsel == -1 ? 0 : prevsel);
306
307     updating_ui = FALSE;
308     return count;
309 }
310
311 static void on_options_click(HWND dialog)
312 {
313     if (IsDlgButtonChecked(dialog, IDC_SHOW_DOT_FILES) == BST_CHECKED)
314         set_reg_key(config_key, "", "ShowDotFiles", "Y");
315     else
316         set_reg_key(config_key, "", "ShowDotFiles", "N");
317
318     SendMessage(GetParent(dialog), PSM_CHANGED, 0, 0);
319 }
320
321 static void on_add_click(HWND dialog)
322 {
323     /* we should allocate a drive letter automatically. We also need
324        some way to let the user choose the mapping point, for now we
325        will just force them to enter a path automatically, with / being
326        the default. In future we should be able to temporarily map /
327        then invoke the directory chooser dialog. */
328
329     char new = 'C'; /* we skip A and B, they are historically floppy drives */
330     long mask = ~drive_available_mask(0); /* the mask is now which drives aren't available */
331     int i, c;
332
333     while (mask & (1 << (new - 'A')))
334     {
335         new++;
336         if (new > 'Z')
337         {
338             MessageBox(dialog, "You cannot add any more drives.\n\nEach drive must have a letter, from A to Z, so you cannot have more than 26", "", MB_OK | MB_ICONEXCLAMATION);
339             return;
340         }
341     }
342
343     WINE_TRACE("allocating drive letter %c\n", new);
344
345     if (new == 'C') add_drive(new, "../drive_c", "System Drive", "", DRIVE_FIXED);
346     else add_drive(new, "/", "", "", DRIVE_UNKNOWN);
347
348     fill_drives_list(dialog);
349
350     /* select the newly created drive */
351     mask = ~drive_available_mask(0);
352     c = 0;
353     for (i = 0; i < 26; i++)
354     {
355         if ('A' + i == new) break;
356         if ((1 << i) & mask) c++;
357     }
358     lv_set_curr_select(dialog, c);
359
360     SetFocus(GetDlgItem(dialog, IDC_LIST_DRIVES));
361
362     update_controls(dialog);
363 }
364
365 static void on_remove_click(HWND dialog)
366 {
367     int itemIndex;
368     struct drive *drive;
369     LVITEM item;
370
371     itemIndex = lv_get_curr_select(dialog);
372     if (itemIndex == -1) return; /* no selection */
373
374     memset(&item, 0, sizeof(item));
375     item.mask = LVIF_PARAM;
376     item.iItem = itemIndex;
377     item.iSubItem = 0;
378
379     lv_get_item(dialog, &item);
380
381     drive = (struct drive *) item.lParam;
382
383     WINE_ERR("unixpath: %s\n", drive->unixpath);
384
385     if (drive->letter == 'C')
386     {
387         DWORD result = MessageBox(dialog, "Are you sure you want to delete drive C?\n\nMost Windows applications expect drive C to exist, and will die messily if it doesn't. If you proceed remember to recreate it!", "", MB_YESNO | MB_ICONEXCLAMATION);
388         if (result == IDNO) return;
389     }
390
391     delete_drive(drive);
392
393     fill_drives_list(dialog);
394
395     itemIndex = itemIndex - 1;
396     if (itemIndex < 0) itemIndex = 0;
397     lv_set_curr_select(dialog, itemIndex);   /* previous item */
398
399     SetFocus(GetDlgItem(dialog, IDC_LIST_DRIVES));
400
401     update_controls(dialog);
402 }
403
404 static void update_controls(HWND dialog)
405 {
406     char *path;
407     unsigned int type;
408     char *label;
409     char *serial;
410     const char *device;
411     int i, selection = -1;
412     LVITEM item;
413
414     updating_ui = TRUE;
415
416     i = lv_get_curr_select(dialog);
417     if (i == -1)
418     {
419         /* no selection? let's select something for the user. this will re-enter */
420         lv_set_curr_select(dialog, i);
421         return;
422     }
423
424     memset(&item, 0, sizeof(item));
425     item.mask = LVIF_PARAM;
426     item.iItem = i;
427     item.iSubItem = 0;
428
429     lv_get_item(dialog, &item);
430     current_drive = (struct drive *) item.lParam;
431
432     WINE_TRACE("Updating sheet for drive %c\n", current_drive->letter);
433
434     /* Drive letters */
435     fill_drive_droplist(drive_available_mask(current_drive->letter), current_drive->letter, dialog);
436
437     /* path */
438     path = current_drive->unixpath;
439     WINE_TRACE("set path control text to '%s'\n", path);
440     set_text(dialog, IDC_EDIT_PATH, path);
441
442     /* drive type */
443     type = current_drive->type;
444     SendDlgItemMessage(dialog, IDC_COMBO_TYPE, CB_RESETCONTENT, 0, 0);
445
446     for (i = 0; i < sizeof(type_pairs) / sizeof(struct drive_typemap); i++)
447     {
448         SendDlgItemMessage(dialog, IDC_COMBO_TYPE, CB_ADDSTRING, 0, (LPARAM) type_pairs[i].sDesc);
449
450         if (type_pairs[i].sCode ==  type)
451         {
452             selection = i;
453         }
454     }
455
456     if (selection == -1) selection = DRIVE_TYPE_DEFAULT;
457     SendDlgItemMessage(dialog, IDC_COMBO_TYPE, CB_SETCURSEL, selection, 0);
458
459     /* removeable media properties */
460     label = current_drive->label;
461     set_text(dialog, IDC_EDIT_LABEL, label);
462
463     /* set serial edit text */
464     serial = current_drive->serial;
465     set_text(dialog, IDC_EDIT_SERIAL, serial);
466
467     /* TODO: get the device here to put into the edit box */
468     device = "Not implemented yet";
469     set_text(dialog, IDC_EDIT_DEVICE, device);
470     device = NULL;
471
472     selection = IDC_RADIO_ASSIGN;
473     if ((type == DRIVE_CDROM) || (type == DRIVE_REMOVABLE))
474     {
475         if (device)
476         {
477             selection = IDC_RADIO_AUTODETECT;
478             enable_labelserial_box(dialog, BOX_MODE_CD_AUTODETECT);
479         }
480         else
481         {
482             selection = IDC_RADIO_ASSIGN;
483             enable_labelserial_box(dialog, BOX_MODE_CD_ASSIGN);
484         }
485     }
486     else
487     {
488         enable_labelserial_box(dialog, BOX_MODE_NORMAL);
489         selection = IDC_RADIO_ASSIGN;
490     }
491
492     CheckRadioButton(dialog, IDC_RADIO_AUTODETECT, IDC_RADIO_ASSIGN, selection);
493
494     updating_ui = FALSE;
495
496     return;
497 }
498
499 static void on_edit_changed(HWND dialog, WORD id)
500 {
501     if (updating_ui) return;
502
503     WINE_TRACE("edit id %d changed\n", id);
504
505     switch (id)
506     {
507         case IDC_EDIT_LABEL:
508         {
509             char *label;
510
511             label = get_text(dialog, id);
512             HeapFree(GetProcessHeap(), 0, current_drive->label);
513             current_drive->label = label ? label :  strdupA("");
514
515             WINE_TRACE("set label to %s\n", current_drive->label);
516
517             /* enable the apply button  */
518             SendMessage(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
519             break;
520         }
521
522         case IDC_EDIT_PATH:
523         {
524             char *path;
525
526             path = get_text(dialog, id);
527             HeapFree(GetProcessHeap(), 0, current_drive->unixpath);
528             current_drive->unixpath = path ? path : strdupA("drive_c");
529
530             WINE_TRACE("set path to %s\n", current_drive->unixpath);
531
532             lv_set_item_text(dialog, lv_get_curr_select(dialog), 1,
533                              current_drive->unixpath);
534
535             /* enable the apply button  */
536             SendMessage(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
537             break;
538         }
539
540         case IDC_EDIT_SERIAL:
541         {
542             char *serial;
543
544             serial = get_text(dialog, id);
545             HeapFree(GetProcessHeap(), 0, current_drive->serial);
546             current_drive->serial = serial ? serial : strdupA("");
547
548             WINE_TRACE("set serial to %s", current_drive->serial);
549
550             /* enable the apply button  */
551             SendMessage(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
552             break;
553         }
554
555         case IDC_EDIT_DEVICE:
556         {
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;
561         }
562     }
563 }
564
565 static void get_etched_rect(HWND dialog, RECT *rect)
566 {
567     GetClientRect(dialog, rect);
568
569     /* these dimensions from the labelserial static in En.rc  */
570     rect->top = 265;
571     rect->bottom = 265;
572     rect->left += 25;
573     rect->right -= 25;
574 }
575
576 /* this just draws a nice line to separate the advanced gui from the n00b gui :) */
577 static void paint(HWND dialog)
578 {
579     PAINTSTRUCT ps;
580
581     BeginPaint(dialog, &ps);
582
583     if (advanced)
584     {
585         RECT rect;
586
587         get_etched_rect(dialog, &rect);
588
589         DrawEdge(ps.hdc, &rect, EDGE_ETCHED, BF_TOP);
590     }
591
592     EndPaint(dialog, &ps);
593 }
594
595 BOOL browse_for_unix_folder(HWND dialog, char *pszPath)
596 {
597     static WCHAR wszUnixRootDisplayName[] = 
598         { ':',':','{','C','C','7','0','2','E','B','2','-','7','D','C','5','-','1','1','D','9','-',
599           'C','6','8','7','-','0','0','0','4','2','3','8','A','0','1','C','D','}', 0 };
600     char pszChoosePath[256];
601     BROWSEINFOA bi = {
602         dialog,
603         NULL,
604         NULL,
605         pszChoosePath,
606         0,
607         NULL,
608         0,
609         0
610     };
611     IShellFolder *pDesktop;
612     LPITEMIDLIST pidlUnixRoot, pidlSelectedPath;
613     HRESULT hr;
614    
615     LoadString(GetModuleHandle(NULL), IDS_CHOOSE_PATH, pszChoosePath, 256);
616     
617     hr = SHGetDesktopFolder(&pDesktop);
618     if (!SUCCEEDED(hr)) return FALSE;
619
620     hr = IShellFolder_ParseDisplayName(pDesktop, NULL, NULL, wszUnixRootDisplayName, NULL, 
621                                        &pidlUnixRoot, NULL);
622     if (!SUCCEEDED(hr)) {
623         IShellFolder_Release(pDesktop);
624         return FALSE;
625     }
626
627     bi.pidlRoot = pidlUnixRoot;
628     pidlSelectedPath = SHBrowseForFolderA(&bi);
629     SHFree(pidlUnixRoot);
630     
631     if (pidlSelectedPath) {
632         STRRET strSelectedPath;
633         char *pszSelectedPath;
634         HRESULT hr;
635         
636         hr = IShellFolder_GetDisplayNameOf(pDesktop, pidlSelectedPath, SHGDN_FORPARSING, 
637                                            &strSelectedPath);
638         IShellFolder_Release(pDesktop);
639         if (!SUCCEEDED(hr)) {
640             SHFree(pidlSelectedPath);
641             return FALSE;
642         }
643
644         hr = StrRetToStr(&strSelectedPath, pidlSelectedPath, &pszSelectedPath);
645         SHFree(pidlSelectedPath);
646         if (!SUCCEEDED(hr)) return FALSE;
647
648         lstrcpy(pszPath, pszSelectedPath);
649         
650         CoTaskMemFree(pszSelectedPath);
651         return TRUE;
652     }
653     return FALSE;
654 }
655
656 static void init_listview_columns(HWND dialog)
657 {
658     LVCOLUMN listColumn;
659     RECT viewRect;
660     int width;
661
662     GetClientRect(GetDlgItem(dialog, IDC_LIST_DRIVES), &viewRect);
663     width = (viewRect.right - viewRect.left) / 6 - 5;
664
665     listColumn.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
666     listColumn.pszText = (char*) "Letter";
667     listColumn.cchTextMax = lstrlen(listColumn.pszText);
668     listColumn.cx = width;
669
670     SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LVM_INSERTCOLUMN, 0, (LPARAM) &listColumn);
671
672     listColumn.cx = viewRect.right - viewRect.left - width;
673     listColumn.pszText = (char*) "Drive Mapping";
674     listColumn.cchTextMax = lstrlen(listColumn.pszText);
675
676     SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LVM_INSERTCOLUMN, 1, (LPARAM) &listColumn);
677 }
678
679 static void load_drive_options(HWND dialog)
680 {
681     if (!strcmp(get_reg_key(config_key, "", "ShowDotFiles", "N"), "Y"))
682         CheckDlgButton(dialog, IDC_SHOW_DOT_FILES, BST_CHECKED);
683 }
684
685 INT_PTR CALLBACK
686 DriveDlgProc (HWND dialog, UINT msg, WPARAM wParam, LPARAM lParam)
687 {
688     int item;
689     struct drive *drive;
690
691     switch (msg)
692     {
693         case WM_INITDIALOG:
694             init_listview_columns(dialog);
695             load_drives();
696             load_drive_options(dialog);
697
698             if (!drives[2].in_use)
699                 MessageBox(dialog, "You don't have a drive C. This is not so great.\n\nRemember to click 'Add' in the Drives tab to create one!\n", "", MB_OK | MB_ICONEXCLAMATION);
700
701             fill_drives_list(dialog);
702             update_controls(dialog);
703             /* put in non-advanced mode by default  */
704             set_advanced(dialog);
705             break;
706
707         case WM_SHOWWINDOW:
708             set_window_title(dialog);
709             break;
710
711         case WM_PAINT:
712             paint(dialog);
713             break;
714
715         case WM_COMMAND:
716             switch (HIWORD(wParam))
717             {
718                 case EN_CHANGE:
719                     on_edit_changed(dialog, LOWORD(wParam));
720                     break;
721
722                 case BN_CLICKED:
723                     switch (LOWORD(wParam))
724                     {
725                         case IDC_SHOW_DOT_FILES:
726                             on_options_click(dialog);
727                         break;
728                     }
729                     break;
730
731                 case CBN_SELCHANGE:
732                     SendMessage(GetParent(dialog), PSM_CHANGED, 0, 0);
733                     break;
734             }
735
736             switch (LOWORD(wParam))
737             {
738                 case IDC_BUTTON_ADD:
739                     if (HIWORD(wParam) != BN_CLICKED) break;
740                     on_add_click(dialog);
741                     break;
742
743                 case IDC_BUTTON_REMOVE:
744                     if (HIWORD(wParam) != BN_CLICKED) break;
745                     on_remove_click(dialog);
746                     break;
747
748                 case IDC_BUTTON_EDIT:
749                     if (HIWORD(wParam) != BN_CLICKED) break;
750                     item = SendMessage(GetDlgItem(dialog, IDC_LIST_DRIVES),  LB_GETCURSEL, 0, 0);
751                     drive = (struct drive *) SendMessage(GetDlgItem(dialog, IDC_LIST_DRIVES), LB_GETITEMDATA, item, 0);
752                     /*DialogBoxParam(NULL, MAKEINTRESOURCE(IDD_DRIVE_EDIT), NULL, (DLGPROC) DriveEditDlgProc, (LPARAM) drive); */
753                     break;
754
755                 case IDC_BUTTON_AUTODETECT:
756                     autodetect_drives();
757                     fill_drives_list(dialog);
758                     SendMessage(GetParent(dialog), PSM_CHANGED, 0, 0);
759                     break;
760
761                 case IDC_BUTTON_SHOW_HIDE_ADVANCED:
762                     advanced = !advanced;
763                     set_advanced(dialog);
764                     break;
765
766                 case IDC_BUTTON_BROWSE_PATH:
767                 {
768                     char szTargetPath[FILENAME_MAX];
769                     if (browse_for_unix_folder(dialog, szTargetPath)) 
770                         set_text(dialog, IDC_EDIT_PATH, szTargetPath);
771                     break;
772                 }
773
774                 case IDC_RADIO_ASSIGN:
775                 {
776                     char *str;
777
778                     str = get_text(dialog, IDC_EDIT_LABEL);
779                     HeapFree(GetProcessHeap(), 0, current_drive->label);
780                     current_drive->label = str ? str : strdupA("");
781
782                     str = get_text(dialog, IDC_EDIT_SERIAL);
783                     HeapFree(GetProcessHeap(), 0, current_drive->serial);
784                     current_drive->serial = str ? str : strdupA("");
785
786                     /* TODO: we don't have a device at this point */
787
788                     enable_labelserial_box(dialog, BOX_MODE_CD_ASSIGN);
789
790                     break;
791                 }
792
793
794                 case IDC_COMBO_TYPE:
795                 {
796                     int mode = BOX_MODE_NORMAL;
797                     int selection;
798
799                     if (HIWORD(wParam) != CBN_SELCHANGE) break;
800
801                     selection = SendDlgItemMessage(dialog, IDC_COMBO_TYPE, CB_GETCURSEL, 0, 0);
802
803                     if (selection >= 0 &&
804                         (type_pairs[selection].sCode == DRIVE_CDROM ||
805                          type_pairs[selection].sCode == DRIVE_REMOVABLE))
806                     {
807                         if (IsDlgButtonChecked(dialog, IDC_RADIO_AUTODETECT))
808                             mode = BOX_MODE_CD_AUTODETECT;
809                         else
810                             mode = BOX_MODE_CD_ASSIGN;
811                     }
812
813                     enable_labelserial_box(dialog, mode);
814
815                     current_drive->type = type_pairs[selection].sCode;
816                     break;
817                 }
818
819             }
820             break;
821
822         case WM_NOTIFY:
823             switch (((LPNMHDR)lParam)->code)
824             {
825                 case PSN_KILLACTIVE:
826                     WINE_TRACE("PSN_KILLACTIVE\n");
827                     SetWindowLongPtr(dialog, DWLP_MSGRESULT, FALSE);
828                     break;
829                 case PSN_APPLY:
830                     apply_drive_changes();
831                     SetWindowLongPtr(dialog, DWLP_MSGRESULT, PSNRET_NOERROR);
832                     break;
833                 case PSN_SETACTIVE:
834                     break;
835                 case LVN_ITEMCHANGED:
836                 {
837                     LPNMLISTVIEW lpnm = (LPNMLISTVIEW)lParam;
838                     if (!(lpnm->uOldState & LVIS_SELECTED) &&
839                          (lpnm->uNewState & LVIS_SELECTED))
840                     update_controls(dialog);
841                     break;
842                 }
843             }
844             break;
845     }
846
847     return FALSE;
848 }