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