Move a fixed size buffer to the heap.
[wine/multimedia.git] / programs / winecfg / driveui.c
blob7a3f635579ceeb7179b55789894d179963673319
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <stdarg.h>
25 #include <stdio.h>
27 #define COBJMACROS
29 #include <windef.h>
30 #include <winbase.h>
31 #include <winreg.h>
32 #include <shellapi.h>
33 #include <objbase.h>
34 #include <shlguid.h>
35 #include <shlwapi.h>
36 #include <shlobj.h>
37 #include <winuser.h>
39 #include <wine/debug.h>
41 #include "winecfg.h"
42 #include "resource.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
46 #define BOX_MODE_CD_ASSIGN 1
47 #define BOX_MODE_CD_AUTODETECT 2
48 #define BOX_MODE_NONE 3
49 #define BOX_MODE_NORMAL 4
51 static BOOL advanced = FALSE;
52 static BOOL updating_ui = FALSE;
53 static struct drive* current_drive;
55 static void get_etched_rect(HWND dialog, RECT *rect);
56 static void update_controls(HWND dialog);
58 /**** listview helper functions ****/
60 /* clears the item at index in the listview */
61 static void lv_clear_curr_select(HWND dialog, int index)
63 ListView_SetItemState(GetDlgItem(dialog, IDC_LIST_DRIVES), index, 0, LVIS_SELECTED);
66 /* selects the item at index in the listview */
67 static void lv_set_curr_select(HWND dialog, int index)
69 /* no more than one item can be selected in our listview */
70 lv_clear_curr_select(dialog, -1);
71 ListView_SetItemState(GetDlgItem(dialog, IDC_LIST_DRIVES), index, LVIS_SELECTED, LVIS_SELECTED);
74 /* returns the currently selected item in the listview */
75 static int lv_get_curr_select(HWND dialog)
77 return SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LVM_GETNEXTITEM, -1, LVNI_SELECTED);
80 /* sets the item in the listview at item->iIndex */
81 static void lv_set_item(HWND dialog, LVITEM *item)
83 SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LVM_SETITEM, 0, (LPARAM) item);
86 /* inserts an item into the listview */
87 static void lv_insert_item(HWND dialog, LVITEM *item)
89 SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LVM_INSERTITEM, 0, (LPARAM) item);
92 /* retrieve the item at index item->iIndex */
93 static void lv_get_item(HWND dialog, LVITEM *item)
95 SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LVM_GETITEM, 0, (LPARAM) item);
98 static void set_advanced(HWND dialog)
100 int state;
101 char text[256];
102 RECT rect;
104 if (advanced)
106 state = SW_NORMAL;
107 LoadString(GetModuleHandle(NULL), IDS_HIDE_ADVANCED, text, 256);
109 else
111 state = SW_HIDE;
112 LoadString(GetModuleHandle(NULL), IDS_SHOW_ADVANCED, text, 256);
115 ShowWindow(GetDlgItem(dialog, IDC_RADIO_AUTODETECT), state);
116 ShowWindow(GetDlgItem(dialog, IDC_RADIO_ASSIGN), state);
117 ShowWindow(GetDlgItem(dialog, IDC_EDIT_LABEL), state);
118 ShowWindow(GetDlgItem(dialog, IDC_EDIT_DEVICE), state);
119 ShowWindow(GetDlgItem(dialog, IDC_STATIC_LABEL), state);
120 ShowWindow(GetDlgItem(dialog, IDC_BUTTON_BROWSE_DEVICE), state);
121 ShowWindow(GetDlgItem(dialog, IDC_EDIT_SERIAL), state);
122 ShowWindow(GetDlgItem(dialog, IDC_STATIC_SERIAL), state);
123 ShowWindow(GetDlgItem(dialog, IDC_LABELSERIAL_STATIC), state);
125 /* update the button text based on the state */
126 SetWindowText(GetDlgItem(dialog, IDC_BUTTON_SHOW_HIDE_ADVANCED), text);
128 /* redraw for the etched line */
129 get_etched_rect(dialog, &rect);
130 InflateRect(&rect, 5, 5);
131 InvalidateRect(dialog, &rect, TRUE);
134 struct drive_typemap {
135 unsigned int sCode;
136 const char *sDesc;
139 static const struct drive_typemap type_pairs[] = {
140 { DRIVE_FIXED, "Local hard disk" },
141 { DRIVE_REMOTE, "Network share" },
142 { DRIVE_REMOVABLE, "Floppy disk" },
143 { DRIVE_CDROM, "CD-ROM" }
146 #define DRIVE_TYPE_DEFAULT 1
148 static void fill_drive_droplist(long mask, char curletter, HWND dialog)
150 int i;
151 int selection;
152 int count;
153 int next_letter;
154 char sName[4];
156 strcpy(sName, "A:");
157 for (i = 0, count = 0, selection = -1, next_letter = -1; i <= 'Z'-'A'; ++i)
159 if (mask & DRIVE_MASK_BIT('A' + i))
161 int index;
163 sName[0] = 'A' + i;
164 index = SendDlgItemMessage(dialog, IDC_COMBO_LETTER, CB_ADDSTRING, 0, (LPARAM) sName);
166 if (toupper(curletter) == 'A' + i)
168 selection = count;
171 if (i >= 2 && next_letter == -1)
173 /* default drive is first one of C-Z */
174 next_letter = count;
177 count++;
181 if (selection == -1)
183 selection = next_letter;
186 SendDlgItemMessage(dialog, IDC_COMBO_LETTER, CB_SETCURSEL, selection, 0);
190 static void enable_labelserial_box(HWND dialog, int mode)
192 WINE_TRACE("mode=%d\n", mode);
194 switch (mode)
196 case BOX_MODE_CD_ASSIGN:
197 enable(IDC_RADIO_ASSIGN);
198 disable(IDC_EDIT_DEVICE);
199 disable(IDC_BUTTON_BROWSE_DEVICE);
200 enable(IDC_EDIT_SERIAL);
201 enable(IDC_EDIT_LABEL);
202 enable(IDC_STATIC_SERIAL);
203 enable(IDC_STATIC_LABEL);
204 break;
206 case BOX_MODE_CD_AUTODETECT:
207 enable(IDC_RADIO_ASSIGN);
208 enable(IDC_EDIT_DEVICE);
209 enable(IDC_BUTTON_BROWSE_DEVICE);
210 disable(IDC_EDIT_SERIAL);
211 disable(IDC_EDIT_LABEL);
212 disable(IDC_STATIC_SERIAL);
213 disable(IDC_STATIC_LABEL);
214 break;
216 case BOX_MODE_NONE:
217 disable(IDC_RADIO_ASSIGN);
218 disable(IDC_EDIT_DEVICE);
219 disable(IDC_BUTTON_BROWSE_DEVICE);
220 disable(IDC_EDIT_SERIAL);
221 disable(IDC_EDIT_LABEL);
222 disable(IDC_STATIC_SERIAL);
223 disable(IDC_STATIC_LABEL);
224 break;
226 case BOX_MODE_NORMAL:
227 enable(IDC_RADIO_ASSIGN);
228 disable(IDC_EDIT_DEVICE);
229 disable(IDC_BUTTON_BROWSE_DEVICE);
230 enable(IDC_EDIT_SERIAL);
231 enable(IDC_EDIT_LABEL);
232 enable(IDC_STATIC_SERIAL);
233 enable(IDC_STATIC_LABEL);
234 break;
238 static int fill_drives_list(HWND dialog)
240 int count = 0;
241 BOOL drivec_present = FALSE;
242 int i;
243 int prevsel = -1;
245 WINE_TRACE("\n");
247 updating_ui = TRUE;
249 prevsel = lv_get_curr_select(dialog);
251 /* Clear the listbox */
252 SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LVM_DELETEALLITEMS, 0, 0);
254 for(i = 0; i < 26; i++)
256 LVITEM item;
257 char *letter = 0;
258 int len;
260 /* skip over any unused drives */
261 if (!drives[i].in_use)
262 continue;
264 if (drives[i].letter == 'C')
265 drivec_present = TRUE;
267 len = snprintf(letter, 0, "%c:", 'A' + i);
268 len++; /* add a byte for the trailing null */
270 letter = HeapAlloc(GetProcessHeap(), 0, len);
271 snprintf(letter, len, "%c:", 'A' + i);
273 memset(&item, 0, sizeof(item));
274 item.mask = LVIF_TEXT;
275 item.iItem = count;
276 item.iSubItem = 0;
277 item.pszText = letter;
278 item.cchTextMax = lstrlen(item.pszText);
280 lv_insert_item(dialog, &item);
282 item.iSubItem = 1;
283 item.pszText = drives[i].unixpath;
284 item.cchTextMax = lstrlen(item.pszText);
286 lv_set_item(dialog, &item);
288 item.mask = LVIF_PARAM;
289 item.iSubItem = 0;
290 item.lParam = (LPARAM) &drives[i];
292 lv_set_item(dialog, &item);
294 HeapFree(GetProcessHeap(), 0, letter);
295 count++;
298 WINE_TRACE("loaded %d drives\n", count);
300 /* show the warning if there is no Drive C */
301 if (!drivec_present)
302 ShowWindow(GetDlgItem(dialog, IDS_DRIVE_NO_C), SW_NORMAL);
303 else
304 ShowWindow(GetDlgItem(dialog, IDS_DRIVE_NO_C), SW_HIDE);
306 lv_set_curr_select(dialog, prevsel == -1 ? 0 : prevsel);
308 updating_ui = FALSE;
309 return count;
312 static void on_options_click(HWND dialog)
314 if (IsDlgButtonChecked(dialog, IDC_SHOW_DIRSYM_LINK) == BST_CHECKED)
315 set_reg_key(config_key, "", "ShowDirSymLinks", "Y");
316 else
317 set_reg_key(config_key, "", "ShowDirSymLinks", "N");
319 if (IsDlgButtonChecked(dialog, IDC_SHOW_DOT_FILES) == BST_CHECKED)
320 set_reg_key(config_key, "", "ShowDotFiles", "Y");
321 else
322 set_reg_key(config_key, "", "ShowDotFiles", "N");
325 static void on_add_click(HWND dialog)
327 /* we should allocate a drive letter automatically. We also need
328 some way to let the user choose the mapping point, for now we
329 will just force them to enter a path automatically, with / being
330 the default. In future we should be able to temporarily map /
331 then invoke the directory chooser dialog. */
333 char new = 'C'; /* we skip A and B, they are historically floppy drives */
334 long mask = ~drive_available_mask(0); /* the mask is now which drives aren't available */
335 int i, c;
337 while (mask & (1 << (new - 'A')))
339 new++;
340 if (new > 'Z')
342 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);
343 return;
347 WINE_TRACE("allocating drive letter %c\n", new);
349 if (new == 'C') add_drive(new, "../drive_c", "System Drive", "", DRIVE_FIXED);
350 else add_drive(new, "/", "", "", DRIVE_FIXED);
352 fill_drives_list(dialog);
354 /* select the newly created drive */
355 mask = ~drive_available_mask(0);
356 c = 0;
357 for (i = 0; i < 26; i++)
359 if ('A' + i == new) break;
360 if ((1 << i) & mask) c++;
362 lv_set_curr_select(dialog, c);
364 SetFocus(GetDlgItem(dialog, IDC_LIST_DRIVES));
366 update_controls(dialog);
369 static void on_remove_click(HWND dialog)
371 int itemIndex;
372 struct drive *drive;
373 LVITEM item;
375 itemIndex = lv_get_curr_select(dialog);
376 if (itemIndex == -1) return; /* no selection */
378 memset(&item, 0, sizeof(item));
379 item.mask = LVIF_PARAM;
380 item.iItem = itemIndex;
381 item.iSubItem = 0;
383 lv_get_item(dialog, &item);
385 drive = (struct drive *) item.lParam;
387 WINE_ERR("unixpath: %s\n", drive->unixpath);
389 if (drive->letter == 'C')
391 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);
392 if (result == IDNO) return;
395 delete_drive(drive);
397 fill_drives_list(dialog);
399 itemIndex = itemIndex - 1;
400 if (itemIndex < 0) itemIndex = 0;
401 lv_set_curr_select(dialog, itemIndex); /* previous item */
403 SetFocus(GetDlgItem(dialog, IDC_LIST_DRIVES));
405 update_controls(dialog);
408 static void update_controls(HWND dialog)
410 char *path;
411 unsigned int type;
412 char *label;
413 char *serial;
414 const char *device;
415 int i, selection = -1;
416 LVITEM item;
418 updating_ui = TRUE;
420 i = lv_get_curr_select(dialog);
421 if (i == -1)
423 /* no selection? let's select something for the user. this will re-enter */
424 lv_set_curr_select(dialog, i);
425 return;
428 memset(&item, 0, sizeof(item));
429 item.mask = LVIF_PARAM;
430 item.iItem = i;
431 item.iSubItem = 0;
433 lv_get_item(dialog, &item);
434 current_drive = (struct drive *) item.lParam;
436 WINE_TRACE("Updating sheet for drive %c\n", current_drive->letter);
438 /* Drive letters */
439 fill_drive_droplist(drive_available_mask(current_drive->letter), current_drive->letter, dialog);
441 /* path */
442 path = current_drive->unixpath;
443 WINE_TRACE("set path control text to '%s'\n", path);
444 set_text(dialog, IDC_EDIT_PATH, path);
446 /* drive type */
447 type = current_drive->type;
448 if (type)
450 SendDlgItemMessage(dialog, IDC_COMBO_TYPE, CB_RESETCONTENT, 0, 0);
452 for (i = 0; i < sizeof(type_pairs) / sizeof(struct drive_typemap); i++)
454 SendDlgItemMessage(dialog, IDC_COMBO_TYPE, CB_ADDSTRING, 0, (LPARAM) type_pairs[i].sDesc);
456 if (type_pairs[i].sCode == type)
458 selection = i;
462 if (selection == -1) selection = DRIVE_TYPE_DEFAULT;
463 SendDlgItemMessage(dialog, IDC_COMBO_TYPE, CB_SETCURSEL, selection, 0);
464 } else WINE_WARN("no Type field?\n");
467 /* removeable media properties */
468 label = current_drive->label;
469 set_text(dialog, IDC_EDIT_LABEL, label);
471 /* set serial edit text */
472 serial = current_drive->serial;
473 set_text(dialog, IDC_EDIT_SERIAL, serial);
475 /* TODO: get the device here to put into the edit box */
476 device = "Not implemented yet";
477 set_text(dialog, IDC_EDIT_DEVICE, device);
478 device = NULL;
480 selection = IDC_RADIO_ASSIGN;
481 if ((type == DRIVE_CDROM) || (type == DRIVE_REMOVABLE))
483 if (device)
485 selection = IDC_RADIO_AUTODETECT;
486 enable_labelserial_box(dialog, BOX_MODE_CD_AUTODETECT);
488 else
490 selection = IDC_RADIO_ASSIGN;
491 enable_labelserial_box(dialog, BOX_MODE_CD_ASSIGN);
494 else
496 enable_labelserial_box(dialog, BOX_MODE_NORMAL);
497 selection = IDC_RADIO_ASSIGN;
500 CheckRadioButton(dialog, IDC_RADIO_AUTODETECT, IDC_RADIO_ASSIGN, selection);
502 updating_ui = FALSE;
504 return;
507 static void on_edit_changed(HWND dialog, WORD id)
509 if (updating_ui) return;
511 WINE_TRACE("edit id %d changed\n", id);
513 /* using fill_drives_list here is pretty lazy, but i'm tired
515 fortunately there are only 26 letters in the alphabet, so
516 we don't have to worry about efficiency too much here :) */
518 switch (id)
520 case IDC_EDIT_LABEL:
522 char *label;
524 label = get_text(dialog, id);
525 HeapFree(GetProcessHeap(), 0, current_drive->label);
526 current_drive->label = label ? label : strdupA("");
528 WINE_TRACE("set label to %s\n", current_drive->label);
530 fill_drives_list(dialog);
531 break;
534 case IDC_EDIT_PATH:
536 char *path;
538 path = get_text(dialog, id);
539 HeapFree(GetProcessHeap(), 0, current_drive->unixpath);
540 current_drive->unixpath = path ? path : strdupA("drive_c");
542 WINE_TRACE("set path to %s\n", current_drive->unixpath);
544 fill_drives_list(dialog);
545 break;
548 case IDC_EDIT_SERIAL:
550 char *serial;
552 serial = get_text(dialog, id);
553 HeapFree(GetProcessHeap(), 0, current_drive->serial);
554 current_drive->serial = serial ? serial : strdupA("");
556 WINE_TRACE("set serial to %s", current_drive->serial);
558 break;
561 case IDC_EDIT_DEVICE:
563 char *device = get_text(dialog, id);
564 /* TODO: handle device if/when it makes sense to do so.... */
565 HeapFree(GetProcessHeap(), 0, device);
566 fill_drives_list(dialog);
567 break;
572 static void get_etched_rect(HWND dialog, RECT *rect)
574 GetClientRect(dialog, rect);
576 /* these dimensions from the labelserial static in En.rc */
577 rect->top = 265;
578 rect->bottom = 265;
579 rect->left += 25;
580 rect->right -= 25;
583 /* this just draws a nice line to separate the advanced gui from the n00b gui :) */
584 static void paint(HWND dialog)
586 PAINTSTRUCT ps;
588 BeginPaint(dialog, &ps);
590 if (advanced)
592 RECT rect;
594 get_etched_rect(dialog, &rect);
596 DrawEdge(ps.hdc, &rect, EDGE_ETCHED, BF_TOP);
599 EndPaint(dialog, &ps);
602 static void browse_for_folder(HWND dialog)
604 static WCHAR wszUnixRootDisplayName[] =
605 { ':',':','{','C','C','7','0','2','E','B','2','-','7','D','C','5','-','1','1','D','9','-',
606 'C','6','8','7','-','0','0','0','4','2','3','8','A','0','1','C','D','}', 0 };
607 char pszChoosePath[256];
608 BROWSEINFOA bi = {
609 dialog,
610 NULL,
611 NULL,
612 pszChoosePath,
614 NULL,
618 IShellFolder *pDesktop;
619 LPITEMIDLIST pidlUnixRoot, pidlSelectedPath;
620 HRESULT hr;
622 LoadString(GetModuleHandle(NULL), IDS_CHOOSE_PATH, pszChoosePath, 256);
624 hr = SHGetDesktopFolder(&pDesktop);
625 if (!SUCCEEDED(hr)) return;
627 hr = IShellFolder_ParseDisplayName(pDesktop, NULL, NULL, wszUnixRootDisplayName, NULL,
628 &pidlUnixRoot, NULL);
629 if (!SUCCEEDED(hr)) {
630 IShellFolder_Release(pDesktop);
631 return;
634 bi.pidlRoot = pidlUnixRoot;
635 pidlSelectedPath = SHBrowseForFolderA(&bi);
636 SHFree(pidlUnixRoot);
638 if (pidlSelectedPath) {
639 STRRET strSelectedPath;
640 char *pszSelectedPath;
641 HRESULT hr;
643 hr = IShellFolder_GetDisplayNameOf(pDesktop, pidlSelectedPath, SHGDN_FORPARSING,
644 &strSelectedPath);
645 IShellFolder_Release(pDesktop);
646 if (!SUCCEEDED(hr)) {
647 SHFree(pidlSelectedPath);
648 return;
651 hr = StrRetToStr(&strSelectedPath, pidlSelectedPath, &pszSelectedPath);
652 SHFree(pidlSelectedPath);
653 if (!SUCCEEDED(hr)) return;
655 HeapFree(GetProcessHeap(), 0, current_drive->unixpath);
656 current_drive->unixpath = strdupA(pszSelectedPath);
657 fill_drives_list(dialog);
658 update_controls(dialog);
660 CoTaskMemFree(pszSelectedPath);
664 static void init_listview_columns(HWND dialog)
666 LVCOLUMN listColumn;
667 RECT viewRect;
668 int width;
670 GetClientRect(GetDlgItem(dialog, IDC_LIST_DRIVES), &viewRect);
671 width = (viewRect.right - viewRect.left) / 6 - 5;
673 listColumn.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
674 listColumn.pszText = (char*) "Letter";
675 listColumn.cchTextMax = lstrlen(listColumn.pszText);
676 listColumn.cx = width;
678 SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LVM_INSERTCOLUMN, 0, (LPARAM) &listColumn);
680 listColumn.cx = viewRect.right - viewRect.left - width;
681 listColumn.pszText = (char*) "Drive Mapping";
682 listColumn.cchTextMax = lstrlen(listColumn.pszText);
684 SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LVM_INSERTCOLUMN, 1, (LPARAM) &listColumn);
687 static void load_drive_options(HWND dialog)
689 if (!strcmp(get_reg_key(config_key, "", "ShowDirSymLinks", "N"), "Y"))
690 CheckDlgButton(dialog, IDC_SHOW_DIRSYM_LINK, BST_CHECKED);
692 if (!strcmp(get_reg_key(config_key, "", "ShowDotFiles", "N"), "Y"))
693 CheckDlgButton(dialog, IDC_SHOW_DOT_FILES, BST_CHECKED);
696 INT_PTR CALLBACK
697 DriveDlgProc (HWND dialog, UINT msg, WPARAM wParam, LPARAM lParam)
699 int item;
700 struct drive *drive;
702 switch (msg)
704 case WM_INITDIALOG:
705 init_listview_columns(dialog);
706 load_drives();
707 load_drive_options(dialog);
709 if (!drives[2].in_use)
710 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);
712 fill_drives_list(dialog);
713 update_controls(dialog);
714 /* put in non-advanced mode by default */
715 set_advanced(dialog);
716 break;
718 case WM_SHOWWINDOW:
719 set_window_title(dialog);
720 break;
722 case WM_PAINT:
723 paint(dialog);
724 break;
726 case WM_COMMAND:
727 switch (HIWORD(wParam))
729 case EN_CHANGE:
730 on_edit_changed(dialog, LOWORD(wParam));
731 break;
733 case BN_CLICKED:
734 SendMessage(GetParent(dialog), PSM_CHANGED, 0, 0);
736 switch (LOWORD(wParam))
738 case IDC_SHOW_DIRSYM_LINK:
739 case IDC_SHOW_DOT_FILES:
740 on_options_click(dialog);
741 break;
743 break;
746 switch (LOWORD(wParam))
748 case IDC_BUTTON_ADD:
749 if (HIWORD(wParam) != BN_CLICKED) break;
750 on_add_click(dialog);
751 break;
753 case IDC_BUTTON_REMOVE:
754 if (HIWORD(wParam) != BN_CLICKED) break;
755 on_remove_click(dialog);
756 break;
758 case IDC_BUTTON_EDIT:
759 if (HIWORD(wParam) != BN_CLICKED) break;
760 item = SendMessage(GetDlgItem(dialog, IDC_LIST_DRIVES), LB_GETCURSEL, 0, 0);
761 drive = (struct drive *) SendMessage(GetDlgItem(dialog, IDC_LIST_DRIVES), LB_GETITEMDATA, item, 0);
762 /*DialogBoxParam(NULL, MAKEINTRESOURCE(IDD_DRIVE_EDIT), NULL, (DLGPROC) DriveEditDlgProc, (LPARAM) drive); */
763 break;
765 case IDC_BUTTON_AUTODETECT:
766 autodetect_drives();
767 fill_drives_list(dialog);
768 break;
770 case IDC_BUTTON_SHOW_HIDE_ADVANCED:
771 advanced = !advanced;
772 set_advanced(dialog);
773 break;
775 case IDC_BUTTON_BROWSE_PATH:
776 browse_for_folder(dialog);
777 break;
779 case IDC_RADIO_ASSIGN:
781 char *str;
783 str = get_text(dialog, IDC_EDIT_LABEL);
784 HeapFree(GetProcessHeap(), 0, current_drive->label);
785 current_drive->label = str ? str : strdupA("");
787 str = get_text(dialog, IDC_EDIT_SERIAL);
788 HeapFree(GetProcessHeap(), 0, current_drive->serial);
789 current_drive->serial = str ? str : strdupA("");
791 /* TODO: we don't have a device at this point */
793 enable_labelserial_box(dialog, BOX_MODE_CD_ASSIGN);
795 break;
799 case IDC_COMBO_TYPE:
801 int mode = BOX_MODE_NORMAL;
802 int selection;
804 if (HIWORD(wParam) != CBN_SELCHANGE) break;
806 selection = SendDlgItemMessage(dialog, IDC_COMBO_TYPE, CB_GETCURSEL, 0, 0);
808 if (selection == 2 || selection == 3) /* cdrom or floppy */
810 if (IsDlgButtonChecked(dialog, IDC_RADIO_AUTODETECT))
811 mode = BOX_MODE_CD_AUTODETECT;
812 else
813 mode = BOX_MODE_CD_ASSIGN;
816 enable_labelserial_box(dialog, mode);
818 current_drive->type = type_pairs[selection].sCode;
819 break;
823 break;
825 case WM_NOTIFY:
826 switch (((LPNMHDR)lParam)->code)
828 case PSN_KILLACTIVE:
829 WINE_TRACE("PSN_KILLACTIVE\n");
830 SetWindowLongPtr(dialog, DWLP_MSGRESULT, FALSE);
831 break;
832 case PSN_APPLY:
833 apply_drive_changes();
834 SetWindowLongPtr(dialog, DWLP_MSGRESULT, PSNRET_NOERROR);
835 break;
836 case PSN_SETACTIVE:
837 break;
840 switch (((LPNMITEMACTIVATE)lParam)->hdr.code)
842 case NM_CLICK:
843 update_controls(dialog);
844 break;
846 break;
849 return FALSE;