include: Add DDHAL_UPDATEOVERLAYDATA structure.
[wine/multimedia.git] / programs / winecfg / driveui.c
blob623a31e744cbe13ff3abb4cb0ad36bfefc61a110
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/debug.h>
38 #include "winecfg.h"
39 #include "resource.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
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
48 static BOOL advanced = FALSE;
49 static BOOL updating_ui = FALSE;
50 static struct drive* current_drive;
52 static void get_etched_rect(HWND dialog, RECT *rect);
53 static void update_controls(HWND dialog);
55 /**** listview helper functions ****/
57 /* clears the item at index in the listview */
58 static void lv_clear_curr_select(HWND dialog, int index)
60 ListView_SetItemState(GetDlgItem(dialog, IDC_LIST_DRIVES), index, 0, LVIS_SELECTED);
63 /* selects the item at index in the listview */
64 static void lv_set_curr_select(HWND dialog, int index)
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);
71 /* returns the currently selected item in the listview */
72 static int lv_get_curr_select(HWND dialog)
74 return SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LVM_GETNEXTITEM, -1, LVNI_SELECTED);
77 /* sets the item in the listview at item->iIndex */
78 static void lv_set_item(HWND dialog, LVITEM *item)
80 SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LVM_SETITEM, 0, (LPARAM) item);
83 /* sets specified item's text */
84 static void lv_set_item_text(HWND dialog, int item, int subItem, char *text)
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);
96 /* inserts an item into the listview */
97 static void lv_insert_item(HWND dialog, LVITEM *item)
99 SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LVM_INSERTITEM, 0, (LPARAM) item);
102 /* retrieve the item at index item->iIndex */
103 static void lv_get_item(HWND dialog, LVITEM *item)
105 SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LVM_GETITEM, 0, (LPARAM) item);
108 static void set_advanced(HWND dialog)
110 int state;
111 char text[256];
112 RECT rect;
114 if (advanced)
116 state = SW_NORMAL;
117 LoadString(GetModuleHandle(NULL), IDS_HIDE_ADVANCED, text, 256);
119 else
121 state = SW_HIDE;
122 LoadString(GetModuleHandle(NULL), IDS_SHOW_ADVANCED, text, 256);
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);
137 /* update the button text based on the state */
138 SetWindowText(GetDlgItem(dialog, IDC_BUTTON_SHOW_HIDE_ADVANCED), text);
140 /* redraw for the etched line */
141 get_etched_rect(dialog, &rect);
142 InflateRect(&rect, 5, 5);
143 InvalidateRect(dialog, &rect, TRUE);
146 struct drive_typemap {
147 unsigned int sCode;
148 const char *sDesc;
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" }
159 #define DRIVE_TYPE_DEFAULT 0
161 static void fill_drive_droplist(long mask, char curletter, HWND dialog)
163 int i;
164 int selection;
165 int count;
166 int next_letter;
167 char sName[4];
169 strcpy(sName, "A:");
170 for (i = 0, count = 0, selection = -1, next_letter = -1; i <= 'Z'-'A'; ++i)
172 if (mask & DRIVE_MASK_BIT('A' + i))
174 int index;
176 sName[0] = 'A' + i;
177 index = SendDlgItemMessage(dialog, IDC_COMBO_LETTER, CB_ADDSTRING, 0, (LPARAM) sName);
179 if (toupper(curletter) == 'A' + i)
181 selection = count;
184 if (i >= 2 && next_letter == -1)
186 /* default drive is first one of C-Z */
187 next_letter = count;
190 count++;
194 if (selection == -1)
196 selection = next_letter;
199 SendDlgItemMessage(dialog, IDC_COMBO_LETTER, CB_SETCURSEL, selection, 0);
203 static void enable_labelserial_box(HWND dialog, int mode)
205 WINE_TRACE("mode=%d\n", mode);
207 switch (mode)
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;
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;
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;
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;
251 static int fill_drives_list(HWND dialog)
253 int count = 0;
254 BOOL drivec_present = FALSE;
255 int i;
256 int prevsel = -1;
258 WINE_TRACE("\n");
260 updating_ui = TRUE;
262 prevsel = lv_get_curr_select(dialog);
264 /* Clear the listbox */
265 SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LVM_DELETEALLITEMS, 0, 0);
267 for(i = 0; i < 26; i++)
269 LVITEM item;
270 char letter[4];
272 /* skip over any unused drives */
273 if (!drives[i].in_use)
274 continue;
276 if (drives[i].letter == 'C')
277 drivec_present = TRUE;
279 letter[0] = 'A' + i;
280 letter[1] = ':';
281 letter[2] = 0;
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];
291 lv_insert_item(dialog, &item);
292 lv_set_item_text(dialog, count, 1, drives[i].unixpath);
294 count++;
297 WINE_TRACE("loaded %d drives\n", count);
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);
305 lv_set_curr_select(dialog, prevsel == -1 ? 0 : prevsel);
307 updating_ui = FALSE;
308 return count;
311 static void on_options_click(HWND dialog)
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");
318 SendMessage(GetParent(dialog), PSM_CHANGED, 0, 0);
321 static void on_add_click(HWND dialog)
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. */
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;
333 while (mask & (1 << (new - 'A')))
335 new++;
336 if (new > 'Z')
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;
343 WINE_TRACE("allocating drive letter %c\n", new);
345 if (new == 'C') add_drive(new, "../drive_c", "System Drive", "", DRIVE_FIXED);
346 else add_drive(new, "/", "", "", DRIVE_UNKNOWN);
348 fill_drives_list(dialog);
350 /* select the newly created drive */
351 mask = ~drive_available_mask(0);
352 c = 0;
353 for (i = 0; i < 26; i++)
355 if ('A' + i == new) break;
356 if ((1 << i) & mask) c++;
358 lv_set_curr_select(dialog, c);
360 SetFocus(GetDlgItem(dialog, IDC_LIST_DRIVES));
362 update_controls(dialog);
365 static void on_remove_click(HWND dialog)
367 int itemIndex;
368 struct drive *drive;
369 LVITEM item;
371 itemIndex = lv_get_curr_select(dialog);
372 if (itemIndex == -1) return; /* no selection */
374 memset(&item, 0, sizeof(item));
375 item.mask = LVIF_PARAM;
376 item.iItem = itemIndex;
377 item.iSubItem = 0;
379 lv_get_item(dialog, &item);
381 drive = (struct drive *) item.lParam;
383 WINE_ERR("unixpath: %s\n", drive->unixpath);
385 if (drive->letter == 'C')
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;
391 delete_drive(drive);
393 fill_drives_list(dialog);
395 itemIndex = itemIndex - 1;
396 if (itemIndex < 0) itemIndex = 0;
397 lv_set_curr_select(dialog, itemIndex); /* previous item */
399 SetFocus(GetDlgItem(dialog, IDC_LIST_DRIVES));
401 update_controls(dialog);
404 static void update_controls(HWND dialog)
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;
414 updating_ui = TRUE;
416 i = lv_get_curr_select(dialog);
417 if (i == -1)
419 /* no selection? let's select something for the user. this will re-enter */
420 lv_set_curr_select(dialog, i);
421 return;
424 memset(&item, 0, sizeof(item));
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 /* Drive letters */
435 fill_drive_droplist(drive_available_mask(current_drive->letter), current_drive->letter, dialog);
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);
442 /* drive type */
443 type = current_drive->type;
444 SendDlgItemMessage(dialog, IDC_COMBO_TYPE, CB_RESETCONTENT, 0, 0);
446 for (i = 0; i < sizeof(type_pairs) / sizeof(struct drive_typemap); i++)
448 SendDlgItemMessage(dialog, IDC_COMBO_TYPE, CB_ADDSTRING, 0, (LPARAM) type_pairs[i].sDesc);
450 if (type_pairs[i].sCode == type)
452 selection = i;
456 if (selection == -1) selection = DRIVE_TYPE_DEFAULT;
457 SendDlgItemMessage(dialog, IDC_COMBO_TYPE, CB_SETCURSEL, selection, 0);
459 /* removeable media properties */
460 label = current_drive->label;
461 set_text(dialog, IDC_EDIT_LABEL, label);
463 /* set serial edit text */
464 serial = current_drive->serial;
465 set_text(dialog, IDC_EDIT_SERIAL, serial);
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;
472 selection = IDC_RADIO_ASSIGN;
473 if ((type == DRIVE_CDROM) || (type == DRIVE_REMOVABLE))
475 if (device)
477 selection = IDC_RADIO_AUTODETECT;
478 enable_labelserial_box(dialog, BOX_MODE_CD_AUTODETECT);
480 else
482 selection = IDC_RADIO_ASSIGN;
483 enable_labelserial_box(dialog, BOX_MODE_CD_ASSIGN);
486 else
488 enable_labelserial_box(dialog, BOX_MODE_NORMAL);
489 selection = IDC_RADIO_ASSIGN;
492 CheckRadioButton(dialog, IDC_RADIO_AUTODETECT, IDC_RADIO_ASSIGN, selection);
494 updating_ui = FALSE;
496 return;
499 static void on_edit_changed(HWND dialog, WORD id)
501 if (updating_ui) return;
503 WINE_TRACE("edit id %d changed\n", id);
505 switch (id)
507 case IDC_EDIT_LABEL:
509 char *label;
511 label = get_text(dialog, id);
512 HeapFree(GetProcessHeap(), 0, current_drive->label);
513 current_drive->label = label ? label : strdupA("");
515 WINE_TRACE("set label to %s\n", current_drive->label);
517 /* enable the apply button */
518 SendMessage(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
519 break;
522 case IDC_EDIT_PATH:
524 char *path;
526 path = get_text(dialog, id);
527 HeapFree(GetProcessHeap(), 0, current_drive->unixpath);
528 current_drive->unixpath = path ? path : strdupA("drive_c");
530 WINE_TRACE("set path to %s\n", current_drive->unixpath);
532 lv_set_item_text(dialog, lv_get_curr_select(dialog), 1,
533 current_drive->unixpath);
535 /* enable the apply button */
536 SendMessage(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
537 break;
540 case IDC_EDIT_SERIAL:
542 char *serial;
544 serial = get_text(dialog, id);
545 HeapFree(GetProcessHeap(), 0, current_drive->serial);
546 current_drive->serial = serial ? serial : strdupA("");
548 WINE_TRACE("set serial to %s", current_drive->serial);
550 /* enable the apply button */
551 SendMessage(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 static void get_etched_rect(HWND dialog, RECT *rect)
567 GetClientRect(dialog, rect);
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;
576 /* this just draws a nice line to separate the advanced gui from the n00b gui :) */
577 static void paint(HWND dialog)
579 PAINTSTRUCT ps;
581 BeginPaint(dialog, &ps);
583 if (advanced)
585 RECT rect;
587 get_etched_rect(dialog, &rect);
589 DrawEdge(ps.hdc, &rect, EDGE_ETCHED, BF_TOP);
592 EndPaint(dialog, &ps);
595 BOOL browse_for_unix_folder(HWND dialog, char *pszPath)
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,
607 NULL,
611 IShellFolder *pDesktop;
612 LPITEMIDLIST pidlUnixRoot, pidlSelectedPath;
613 HRESULT hr;
615 LoadString(GetModuleHandle(NULL), IDS_CHOOSE_PATH, pszChoosePath, 256);
617 hr = SHGetDesktopFolder(&pDesktop);
618 if (!SUCCEEDED(hr)) return FALSE;
620 hr = IShellFolder_ParseDisplayName(pDesktop, NULL, NULL, wszUnixRootDisplayName, NULL,
621 &pidlUnixRoot, NULL);
622 if (!SUCCEEDED(hr)) {
623 IShellFolder_Release(pDesktop);
624 return FALSE;
627 bi.pidlRoot = pidlUnixRoot;
628 pidlSelectedPath = SHBrowseForFolderA(&bi);
629 SHFree(pidlUnixRoot);
631 if (pidlSelectedPath) {
632 STRRET strSelectedPath;
633 char *pszSelectedPath;
634 HRESULT hr;
636 hr = IShellFolder_GetDisplayNameOf(pDesktop, pidlSelectedPath, SHGDN_FORPARSING,
637 &strSelectedPath);
638 IShellFolder_Release(pDesktop);
639 if (!SUCCEEDED(hr)) {
640 SHFree(pidlSelectedPath);
641 return FALSE;
644 hr = StrRetToStr(&strSelectedPath, pidlSelectedPath, &pszSelectedPath);
645 SHFree(pidlSelectedPath);
646 if (!SUCCEEDED(hr)) return FALSE;
648 lstrcpy(pszPath, pszSelectedPath);
650 CoTaskMemFree(pszSelectedPath);
651 return TRUE;
653 return FALSE;
656 static void init_listview_columns(HWND dialog)
658 LVCOLUMN listColumn;
659 RECT viewRect;
660 int width;
662 GetClientRect(GetDlgItem(dialog, IDC_LIST_DRIVES), &viewRect);
663 width = (viewRect.right - viewRect.left) / 6 - 5;
665 listColumn.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
666 listColumn.pszText = (char*) "Letter";
667 listColumn.cchTextMax = lstrlen(listColumn.pszText);
668 listColumn.cx = width;
670 SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LVM_INSERTCOLUMN, 0, (LPARAM) &listColumn);
672 listColumn.cx = viewRect.right - viewRect.left - width;
673 listColumn.pszText = (char*) "Drive Mapping";
674 listColumn.cchTextMax = lstrlen(listColumn.pszText);
676 SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LVM_INSERTCOLUMN, 1, (LPARAM) &listColumn);
679 static void load_drive_options(HWND dialog)
681 if (!strcmp(get_reg_key(config_key, "", "ShowDotFiles", "N"), "Y"))
682 CheckDlgButton(dialog, IDC_SHOW_DOT_FILES, BST_CHECKED);
685 INT_PTR CALLBACK
686 DriveDlgProc (HWND dialog, UINT msg, WPARAM wParam, LPARAM lParam)
688 int item;
689 struct drive *drive;
691 switch (msg)
693 case WM_INITDIALOG:
694 init_listview_columns(dialog);
695 load_drives();
696 load_drive_options(dialog);
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);
701 fill_drives_list(dialog);
702 update_controls(dialog);
703 /* put in non-advanced mode by default */
704 set_advanced(dialog);
705 break;
707 case WM_SHOWWINDOW:
708 set_window_title(dialog);
709 break;
711 case WM_PAINT:
712 paint(dialog);
713 break;
715 case WM_COMMAND:
716 switch (HIWORD(wParam))
718 case EN_CHANGE:
719 on_edit_changed(dialog, LOWORD(wParam));
720 break;
722 case BN_CLICKED:
723 switch (LOWORD(wParam))
725 case IDC_SHOW_DOT_FILES:
726 on_options_click(dialog);
727 break;
729 break;
731 case CBN_SELCHANGE:
732 SendMessage(GetParent(dialog), PSM_CHANGED, 0, 0);
733 break;
736 switch (LOWORD(wParam))
738 case IDC_BUTTON_ADD:
739 if (HIWORD(wParam) != BN_CLICKED) break;
740 on_add_click(dialog);
741 break;
743 case IDC_BUTTON_REMOVE:
744 if (HIWORD(wParam) != BN_CLICKED) break;
745 on_remove_click(dialog);
746 break;
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;
755 case IDC_BUTTON_AUTODETECT:
756 autodetect_drives();
757 fill_drives_list(dialog);
758 SendMessage(GetParent(dialog), PSM_CHANGED, 0, 0);
759 break;
761 case IDC_BUTTON_SHOW_HIDE_ADVANCED:
762 advanced = !advanced;
763 set_advanced(dialog);
764 break;
766 case IDC_BUTTON_BROWSE_PATH:
768 char szTargetPath[FILENAME_MAX];
769 if (browse_for_unix_folder(dialog, szTargetPath))
770 set_text(dialog, IDC_EDIT_PATH, szTargetPath);
771 break;
774 case IDC_RADIO_ASSIGN:
776 char *str;
778 str = get_text(dialog, IDC_EDIT_LABEL);
779 HeapFree(GetProcessHeap(), 0, current_drive->label);
780 current_drive->label = str ? str : strdupA("");
782 str = get_text(dialog, IDC_EDIT_SERIAL);
783 HeapFree(GetProcessHeap(), 0, current_drive->serial);
784 current_drive->serial = str ? str : strdupA("");
786 /* TODO: we don't have a device at this point */
788 enable_labelserial_box(dialog, BOX_MODE_CD_ASSIGN);
790 break;
794 case IDC_COMBO_TYPE:
796 int mode = BOX_MODE_NORMAL;
797 int selection;
799 if (HIWORD(wParam) != CBN_SELCHANGE) break;
801 selection = SendDlgItemMessage(dialog, IDC_COMBO_TYPE, CB_GETCURSEL, 0, 0);
803 if (selection >= 0 &&
804 (type_pairs[selection].sCode == DRIVE_CDROM ||
805 type_pairs[selection].sCode == DRIVE_REMOVABLE))
807 if (IsDlgButtonChecked(dialog, IDC_RADIO_AUTODETECT))
808 mode = BOX_MODE_CD_AUTODETECT;
809 else
810 mode = BOX_MODE_CD_ASSIGN;
813 enable_labelserial_box(dialog, mode);
815 current_drive->type = type_pairs[selection].sCode;
816 break;
820 break;
822 case WM_NOTIFY:
823 switch (((LPNMHDR)lParam)->code)
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:
837 LPNMLISTVIEW lpnm = (LPNMLISTVIEW)lParam;
838 if (!(lpnm->uOldState & LVIS_SELECTED) &&
839 (lpnm->uNewState & LVIS_SELECTED))
840 update_controls(dialog);
841 break;
844 break;
847 return FALSE;