Added a new flag to wrc, to be used to assess translations
[wine.git] / programs / winecfg / drive.c
blobdf0319e7f5fce1fe963e2898a8b70ef55d214d4d
1 /*
2 * Drive management UI code
4 * Copyright 2003 Mark Westcott
5 * Copyright 2003 Mike Hearn
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <assert.h>
24 #include <stdarg.h>
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <string.h>
29 #include <windef.h>
30 #include <winbase.h>
31 #include <winreg.h>
32 #include <wine/debug.h>
33 #include <shellapi.h>
34 #include <objbase.h>
35 #include <shlguid.h>
36 #include <shlwapi.h>
37 #include <shlobj.h>
39 #include "winecfg.h"
40 #include "resource.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
44 static BOOL updatingUI = FALSE;
45 static char editWindowLetter; /* drive letter of the drive we are currently editing */
46 static int lastSel = 0; /* the last drive selected in the property sheet */
49 /* returns NULL on failure. caller is responsible for freeing result */
50 char *getDriveValue(char letter, const char *valueName) {
51 HKEY hkDrive = 0;
52 char *subKeyName;
53 char *result = NULL;
54 HRESULT hr;
55 DWORD bufferSize;
57 WINE_TRACE("letter=%c, valueName=%s\n", letter, valueName);
59 subKeyName = malloc(strlen("Drive X")+1);
60 sprintf(subKeyName, "Drive %c", letter);
62 hr = RegOpenKeyEx(configKey, subKeyName, 0, KEY_READ, &hkDrive);
63 if (hr != ERROR_SUCCESS) goto end;
65 hr = RegQueryValueEx(hkDrive, valueName, NULL, NULL, NULL, &bufferSize);
66 if (hr != ERROR_SUCCESS) goto end;
68 result = malloc(bufferSize);
69 hr = RegQueryValueEx(hkDrive, valueName, NULL, NULL, result, &bufferSize);
70 if (hr != ERROR_SUCCESS) goto end;
72 end:
73 if (hkDrive) RegCloseKey(hkDrive);
74 free(subKeyName);
75 return result;
78 /* call with newValue == NULL to remove a value */
79 void setDriveValue(char letter, const char *valueName, const char *newValue) {
80 char *driveSection = malloc(strlen("Drive X")+1);
81 sprintf(driveSection, "Drive %c", letter);
82 if (newValue)
83 addTransaction(driveSection, valueName, ACTION_SET, newValue);
84 else
85 addTransaction(driveSection, valueName, ACTION_REMOVE, NULL);
86 free(driveSection);
89 /* copies a drive configuration branch */
90 void copyDrive(char srcLetter, char destLetter) {
91 char driveSection[sizeof("Drive X")];
92 char *path, *label, *type, *serial, *fs;
94 WINE_TRACE("srcLetter=%c, destLetter=%c\n", srcLetter, destLetter);
96 sprintf(driveSection, "Drive %c", srcLetter);
97 path = getDriveValue(srcLetter, "Path");
98 label = getDriveValue(srcLetter, "Label");
99 type = getDriveValue(srcLetter, "Type");
100 serial = getDriveValue(srcLetter, "Serial");
101 fs = getDriveValue(srcLetter, "FileSystem");
103 sprintf(driveSection, "Drive %c", destLetter);
104 if (path) addTransaction(driveSection, "Path", ACTION_SET, path);
105 if (label) addTransaction(driveSection, "Label", ACTION_SET, label);
106 if (type) addTransaction(driveSection, "Type", ACTION_SET, type);
107 if (serial) addTransaction(driveSection, "Serial", ACTION_SET, serial);
108 if (fs) addTransaction(driveSection, "FileSystem", ACTION_SET, fs);
110 if (path) free(path);
111 if (label) free(label);
112 if (type) free(type);
113 if (serial) free(serial);
114 if (fs) free(fs);
117 void removeDrive(char letter) {
118 char driveSection[sizeof("Drive X")];
119 sprintf(driveSection, "Drive %c", letter);
120 addTransaction(driveSection, NULL, ACTION_REMOVE, NULL);
123 int refreshDriveDlg (HWND dialog)
125 int i;
126 char *subKeyName = malloc(MAX_NAME_LENGTH);
127 int driveCount = 0;
128 DWORD sizeOfSubKeyName = MAX_NAME_LENGTH;
129 int doesDriveCExist = FALSE;
131 WINE_TRACE("\n");
133 updatingUI = TRUE;
135 /* Clear the listbox */
136 SendMessageA(GetDlgItem(dialog, IDC_LIST_DRIVES), LB_RESETCONTENT, 0, 0);
137 for (i = 0;
138 RegEnumKeyExA(configKey, i, subKeyName, &sizeOfSubKeyName, NULL, NULL, NULL, NULL ) != ERROR_NO_MORE_ITEMS;
139 ++i, sizeOfSubKeyName = MAX_NAME_LENGTH) {
141 HKEY hkDrive;
142 char returnBuffer[MAX_NAME_LENGTH];
143 DWORD sizeOfReturnBuffer = sizeof(returnBuffer);
144 LONG r;
145 WINE_TRACE("%s\n", subKeyName);
147 if (!strncmp("Drive ", subKeyName, 5)) {
148 char driveLetter = '\0';
149 char *label;
150 char *title;
151 char *device;
152 int titleLen;
153 const char *itemLabel = "Drive %s (%s)";
154 int itemIndex;
156 if (RegOpenKeyExA (configKey, subKeyName, 0, KEY_READ, &hkDrive) != ERROR_SUCCESS) {
157 WINE_ERR("unable to open drive registry key");
158 RegCloseKey(configKey);
159 return -1;
162 /* extract the drive letter, force to upper case */
163 driveLetter = subKeyName[strlen(subKeyName)-1];
164 if (driveLetter) driveLetter = toupper(driveLetter);
165 if (driveLetter == 'C') doesDriveCExist = TRUE;
167 ZeroMemory(returnBuffer, sizeof(*returnBuffer));
168 sizeOfReturnBuffer = sizeof(returnBuffer);
169 r = RegQueryValueExA(hkDrive, "Label", NULL, NULL, returnBuffer, &sizeOfReturnBuffer);
170 if (r == ERROR_SUCCESS) {
171 label = malloc(sizeOfReturnBuffer);
172 strncpy(label, returnBuffer, sizeOfReturnBuffer);
173 } else {
174 WINE_WARN("label not loaded: %ld\n", r);
175 label = NULL;
178 device = getDriveValue(driveLetter, "Device");
180 /* We now know the label and drive letter, so we can add to the list. The list items will have the letter associated
181 * with them, which acts as the key. We can then use that letter to get/set the properties of the drive. */
182 WINE_TRACE("Adding %c: label=%s to the listbox, device=%s\n", driveLetter, label, device);
184 /* fixup label */
185 if (!label && device) {
186 label = malloc(strlen("[label read from device ]")+1+strlen(device));
187 sprintf(label, "[label read from device %s]", device);
189 if (!label) label = strdup("(no label)");
191 titleLen = strlen(itemLabel) - 1 + strlen(label) - 2 + 1;
192 title = malloc(titleLen);
193 /* the %s in the item label will be replaced by the drive letter, so -1, then
194 -2 for the second %s which will be expanded to the label, finally + 1 for terminating #0 */
195 snprintf(title, titleLen, "Drive %c: %s", driveLetter, label);
197 /* the first SendMessage call adds the string and returns the index, the second associates that index with it */
198 itemIndex = SendMessageA(GetDlgItem(dialog, IDC_LIST_DRIVES), LB_ADDSTRING ,(WPARAM) -1, (LPARAM) title);
199 SendMessageA(GetDlgItem(dialog, IDC_LIST_DRIVES), LB_SETITEMDATA, itemIndex, (LPARAM) driveLetter);
201 free(title);
202 free(label);
204 driveCount++;
209 WINE_TRACE("loaded %d drives\n", driveCount);
210 SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LB_SETSEL, TRUE, lastSel);
212 /* show the warning if there is no Drive C */
213 if (!doesDriveCExist)
214 ShowWindow(GetDlgItem(dialog, IDS_DRIVE_NO_C), SW_NORMAL);
215 else
216 ShowWindow(GetDlgItem(dialog, IDS_DRIVE_NO_C), SW_HIDE);
218 free(subKeyName);
220 /* disable or enable controls depending on whether we are editing global vs app specific config */
221 if (appSettings == EDITING_GLOBAL) {
222 WINE_TRACE("enabling controls\n");
223 enable(IDC_LIST_DRIVES);
224 enable(IDC_BUTTON_ADD);
225 enable(IDC_BUTTON_REMOVE);
226 enable(IDC_BUTTON_EDIT);
227 enable(IDC_BUTTON_AUTODETECT);
229 } else {
230 WINE_TRACE("disabling controls\n");
231 disable(IDC_LIST_DRIVES);
232 disable(IDC_BUTTON_ADD);
233 disable(IDC_BUTTON_REMOVE);
234 disable(IDC_BUTTON_EDIT);
235 disable(IDC_BUTTON_AUTODETECT);
239 updatingUI = FALSE;
240 return driveCount;
243 /******************************************************************************/
244 /* The Drive Editing Dialog */
245 /******************************************************************************/
246 #define DRIVE_MASK_BIT(B) 1<<(toupper(B)-'A')
248 typedef struct {
249 const char *sCode;
250 const char *sDesc;
251 } code_desc_pair;
253 static code_desc_pair type_pairs[] = {
254 {"hd", "Local hard disk"},
255 {"network", "Network share" },
256 {"floppy", "Floppy disk"},
257 {"cdrom", "CD-ROM"}
259 #define DRIVE_TYPE_DEFAULT 1
261 static code_desc_pair fs_pairs[] = {
262 {"win95", "Long file names"},
263 {"msdos", "MS-DOS 8 character file names"},
264 {"unix", "UNIX file names"}
267 #define DRIVE_FS_DEFAULT 0
270 void fill_drive_droplist(long mask, char currentLetter, HWND hDlg)
272 int i;
273 int selection;
274 int count;
275 int next_letter;
276 char sName[4] = "A:";
278 for( i=0, count=0, selection=-1, next_letter=-1; i <= 'Z'-'A'; ++i ) {
279 if( mask & DRIVE_MASK_BIT('A'+i) ) {
280 int index;
282 sName[0] = 'A' + i;
283 index = SendDlgItemMessage( hDlg, IDC_COMBO_LETTER, CB_ADDSTRING, 0, (LPARAM) sName );
285 if( toupper(currentLetter) == 'A' + i ) {
286 selection = count;
289 if( i >= 2 && next_letter == -1){ /*default drive is first one of C-Z */
290 next_letter = count;
293 count++;
297 if( selection == -1 ) {
298 selection = next_letter;
301 SendDlgItemMessage( hDlg, IDC_COMBO_LETTER, CB_SETCURSEL, selection, 0 );
304 #define BOX_MODE_CD_ASSIGN 1
305 #define BOX_MODE_CD_AUTODETECT 2
306 #define BOX_MODE_NONE 3
307 #define BOX_MODE_NORMAL 4
308 void enable_labelserial_box(HWND dialog, int mode)
310 WINE_TRACE("mode=%d\n", mode);
311 switch (mode) {
312 case BOX_MODE_CD_ASSIGN:
313 enable(IDC_RADIO_AUTODETECT);
314 enable(IDC_RADIO_ASSIGN);
315 disable(IDC_EDIT_DEVICE);
316 disable(IDC_BUTTON_BROWSE_DEVICE);
317 enable(IDC_EDIT_SERIAL);
318 enable(IDC_EDIT_LABEL);
319 enable(IDC_STATIC_SERIAL);
320 enable(IDC_STATIC_LABEL);
321 break;
323 case BOX_MODE_CD_AUTODETECT:
324 enable(IDC_RADIO_AUTODETECT);
325 enable(IDC_RADIO_ASSIGN);
326 enable(IDC_EDIT_DEVICE);
327 enable(IDC_BUTTON_BROWSE_DEVICE);
328 disable(IDC_EDIT_SERIAL);
329 disable(IDC_EDIT_LABEL);
330 disable(IDC_STATIC_SERIAL);
331 disable(IDC_STATIC_LABEL);
332 break;
334 case BOX_MODE_NONE:
335 disable(IDC_RADIO_AUTODETECT);
336 disable(IDC_RADIO_ASSIGN);
337 disable(IDC_EDIT_DEVICE);
338 disable(IDC_BUTTON_BROWSE_DEVICE);
339 disable(IDC_EDIT_SERIAL);
340 disable(IDC_EDIT_LABEL);
341 disable(IDC_STATIC_SERIAL);
342 disable(IDC_STATIC_LABEL);
343 break;
345 case BOX_MODE_NORMAL:
346 disable(IDC_RADIO_AUTODETECT);
347 enable(IDC_RADIO_ASSIGN);
348 disable(IDC_EDIT_DEVICE);
349 disable(IDC_BUTTON_BROWSE_DEVICE);
350 enable(IDC_EDIT_SERIAL);
351 enable(IDC_EDIT_LABEL);
352 enable(IDC_STATIC_SERIAL);
353 enable(IDC_STATIC_LABEL);
354 break;
358 /* This function produces a mask for each drive letter that isn't currently used. Each bit of the long result
359 * represents a letter, with A being the least significant bit, and Z being the most significant.
361 * To calculate this, we loop over each letter, and see if we can get a drive entry for it. If so, we
362 * set the appropriate bit. At the end, we flip each bit, to give the desired result.
364 * The letter parameter is always marked as being available. This is so the edit dialog can display the
365 * currently used drive letter alongside the available ones.
367 long drive_available_mask(char letter)
369 long result = 0;
370 char curLetter;
371 char *slop;
373 WINE_TRACE("\n");
375 for (curLetter = 'A'; curLetter < 'Z'; curLetter++) {
376 slop = getDriveValue(curLetter, "Path");
377 if (slop != NULL) {
378 result |= DRIVE_MASK_BIT(curLetter);
379 free(slop);
383 result = ~result;
384 if (letter) result |= DRIVE_MASK_BIT(letter);
386 WINE_TRACE( "finished drive letter loop with %lx\n", result );
387 return result;
391 void refreshDriveEditDialog(HWND dialog) {
392 char *path;
393 char *type;
394 char *fs;
395 char *serial;
396 char *label;
397 char *device;
398 int i, selection;
400 updatingUI = TRUE;
402 /* Drive letters */
403 fill_drive_droplist( drive_available_mask( editWindowLetter ), editWindowLetter, dialog );
405 /* path */
406 path = getDriveValue(editWindowLetter, "Path");
407 if (path) {
408 SetWindowText(GetDlgItem(dialog, IDC_EDIT_PATH), path);
409 } else WINE_WARN("no Path field?\n");
411 /* drive type */
412 type = getDriveValue(editWindowLetter, "Type");
413 if (type) {
414 for(i = 0, selection = -1; i < sizeof(type_pairs)/sizeof(code_desc_pair); i++) {
415 SendDlgItemMessage(dialog, IDC_COMBO_TYPE, CB_ADDSTRING, 0,
416 (LPARAM) type_pairs[i].sDesc);
417 if(strcasecmp(type_pairs[i].sCode, type) == 0){
418 selection = i;
422 if( selection == -1 ) selection = DRIVE_TYPE_DEFAULT;
423 SendDlgItemMessage(dialog, IDC_COMBO_TYPE, CB_SETCURSEL, selection, 0);
424 } else WINE_WARN("no Type field?\n");
427 /* FileSystem name handling */
428 fs = getDriveValue(editWindowLetter, "FileSystem");
429 if (fs) {
430 for( i=0, selection=-1; i < sizeof(fs_pairs)/sizeof(code_desc_pair); i++) {
431 SendDlgItemMessage(dialog, IDC_COMBO_NAMES, CB_ADDSTRING, 0,
432 (LPARAM) fs_pairs[i].sDesc);
433 if(strcasecmp(fs_pairs[i].sCode, fs) == 0){
434 selection = i;
438 if( selection == -1 ) selection = DRIVE_FS_DEFAULT;
439 SendDlgItemMessage(dialog, IDC_COMBO_NAMES, CB_SETCURSEL, selection, 0);
440 } else WINE_WARN("no FileSystem field?\n");
443 /* removeable media properties */
444 serial = getDriveValue(editWindowLetter, "Serial");
445 if (serial) {
446 SendDlgItemMessage(dialog, IDC_EDIT_SERIAL, WM_SETTEXT, 0,(LPARAM)serial);
447 } else WINE_WARN("no Serial field?\n");
449 label = getDriveValue(editWindowLetter, "Label");
450 if (label) {
451 SendDlgItemMessage(dialog, IDC_EDIT_LABEL, WM_SETTEXT, 0,(LPARAM)label);
452 } else WINE_WARN("no Label field?\n");
454 device = getDriveValue(editWindowLetter, "Device");
455 if (device) {
456 SendDlgItemMessage(dialog, IDC_EDIT_DEVICE, WM_SETTEXT, 0,(LPARAM)device);
457 } else WINE_WARN("no Device field?\n");
459 selection = IDC_RADIO_ASSIGN;
460 if ((type && strcmp("cdrom", type) == 0) || (type && strcmp("floppy", type) == 0)) {
461 if (device) {
462 selection = IDC_RADIO_AUTODETECT;
463 enable_labelserial_box(dialog, BOX_MODE_CD_AUTODETECT);
464 } else {
465 selection = IDC_RADIO_ASSIGN;
466 enable_labelserial_box(dialog, BOX_MODE_CD_ASSIGN);
468 } else {
469 enable_labelserial_box(dialog, BOX_MODE_NORMAL);
470 selection = IDC_RADIO_ASSIGN;
473 CheckRadioButton( dialog, IDC_RADIO_AUTODETECT, IDC_RADIO_ASSIGN, selection );
474 if (path) SendDlgItemMessage(dialog, IDC_EDIT_PATH, WM_SETTEXT, 0,(LPARAM)path);
476 if (path) free(path);
477 if (type) free(type);
478 if (fs) free(fs);
479 if (serial) free(serial);
480 if (label) free(label);
481 if (device) free(device);
484 updatingUI = FALSE;
486 return;
489 /* storing the drive propsheet HWND here is a bit ugly, but the simplest solution for now */
490 static HWND driveDlgHandle;
492 void onEditChanged(HWND hDlg, WORD controlID) {
493 WINE_TRACE("controlID=%d\n", controlID);
494 switch (controlID) {
495 case IDC_EDIT_LABEL: {
496 char *label = getDialogItemText(hDlg, controlID);
497 setDriveValue(editWindowLetter, "Label", label);
498 refreshDriveDlg(driveDlgHandle);
499 if (label) free(label);
500 break;
502 case IDC_EDIT_PATH: {
503 char *path = getDialogItemText(hDlg, controlID);
504 if (!path) path = strdup("fake_windows"); /* default to assuming fake_windows in the .wine directory */
505 setDriveValue(editWindowLetter, "Path", path);
506 free(path);
507 break;
509 case IDC_EDIT_SERIAL: {
510 char *serial = getDialogItemText(hDlg, controlID);
511 setDriveValue(editWindowLetter, "Serial", serial);
512 if (serial) free (serial);
513 break;
515 case IDC_EDIT_DEVICE: {
516 char *device = getDialogItemText(hDlg,controlID);
517 setDriveValue(editWindowLetter, "Device", device);
518 if (device) free(device);
519 refreshDriveDlg(driveDlgHandle);
520 break;
525 INT_PTR CALLBACK DriveEditDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
527 int selection;
529 switch (uMsg) {
530 case WM_INITDIALOG: {
531 editWindowLetter = (char) lParam;
532 refreshDriveEditDialog(hDlg);
535 case WM_COMMAND:
536 switch (LOWORD(wParam)) {
537 case IDC_COMBO_TYPE:
538 if (HIWORD(wParam) != CBN_SELCHANGE) break;
539 selection = SendDlgItemMessage( hDlg, IDC_COMBO_TYPE, CB_GETCURSEL, 0, 0);
540 if( selection == 2 || selection == 3 ) { /* cdrom or floppy */
541 if (IsDlgButtonChecked(hDlg, IDC_RADIO_AUTODETECT))
542 enable_labelserial_box(hDlg, BOX_MODE_CD_AUTODETECT);
543 else
544 enable_labelserial_box(hDlg, BOX_MODE_CD_ASSIGN);
546 else {
547 enable_labelserial_box( hDlg, BOX_MODE_NORMAL );
549 setDriveValue(editWindowLetter, "Type", type_pairs[selection].sCode);
550 break;
552 case IDC_COMBO_LETTER: {
553 int item = SendDlgItemMessage(hDlg, IDC_COMBO_LETTER, CB_GETCURSEL, 0, 0);
554 char newLetter;
555 SendDlgItemMessage(hDlg, IDC_COMBO_LETTER, CB_GETLBTEXT, item, (LPARAM) &newLetter);
557 if (HIWORD(wParam) != CBN_SELCHANGE) break;
558 if (newLetter == editWindowLetter) break;
560 WINE_TRACE("changing drive letter to %c\n", newLetter);
561 copyDrive(editWindowLetter, newLetter);
562 removeDrive(editWindowLetter);
563 editWindowLetter = newLetter;
564 refreshDriveDlg(driveDlgHandle);
565 break;
568 case IDC_BUTTON_BROWSE_PATH:
569 WRITEME(hDlg);
570 break;
572 case IDC_RADIO_AUTODETECT: {
573 setDriveValue(editWindowLetter, "Label", NULL);
574 setDriveValue(editWindowLetter, "Serial", NULL);
575 setDriveValue(editWindowLetter, "Device", getDialogItemText(hDlg, IDC_EDIT_DEVICE));
576 enable_labelserial_box(hDlg, BOX_MODE_CD_AUTODETECT);
577 refreshDriveDlg(driveDlgHandle);
578 break;
581 case IDC_RADIO_ASSIGN:
582 setDriveValue(editWindowLetter, "Device", NULL);
583 setDriveValue(editWindowLetter, "Label", getDialogItemText(hDlg, IDC_EDIT_LABEL));
584 setDriveValue(editWindowLetter, "Serial", getDialogItemText(hDlg, IDC_EDIT_SERIAL));
585 enable_labelserial_box(hDlg, BOX_MODE_CD_ASSIGN);
586 refreshDriveDlg(driveDlgHandle);
587 break;
589 case ID_BUTTON_OK:
590 EndDialog(hDlg, wParam);
591 return TRUE;
593 if (HIWORD(wParam) == EN_CHANGE) onEditChanged(hDlg, LOWORD(wParam));
594 break;
596 return FALSE;
599 void onAddDriveClicked(HWND hDlg) {
600 /* we should allocate a drive letter automatically. We also need some way to let the user choose the mapping point,
601 for now we will just force them to enter a path automatically, with / being the default. In future we should
602 be able to temporarily map / then invoke the directory chooser dialog. */
604 char newLetter = 'C'; /* we skip A and B, they are historically floppy drives */
605 long mask = ~drive_available_mask(0); /* the mask is now which drives aren't available */
606 char *sectionName;
608 while (mask & (1 << (newLetter - 'A'))) {
609 newLetter++;
610 if (newLetter > 'Z') {
611 MessageBox(NULL, "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);
612 return;
615 WINE_TRACE("allocating drive letter %c\n", newLetter);
617 sectionName = malloc(strlen("Drive X") + 1);
618 sprintf(sectionName, "Drive %c", newLetter);
619 if (newLetter == 'C') {
620 addTransaction(sectionName, "Path", ACTION_SET, "fake_windows");
621 addTransaction(sectionName, "Label", ACTION_SET, "System Drive");
622 } else
623 addTransaction(sectionName, "Path", ACTION_SET, "/"); /* default to root path */
624 addTransaction(sectionName, "Type", ACTION_SET, "hd");
625 processTransQueue(); /* make sure the drive has been added, even if we are not in instant apply mode */
626 free(sectionName);
628 refreshDriveDlg(driveDlgHandle);
630 DialogBoxParam(NULL, MAKEINTRESOURCE(IDD_DRIVE_EDIT), NULL, (DLGPROC) DriveEditDlgProc, (LPARAM) newLetter);
634 INT_PTR CALLBACK
635 DriveDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
637 int selection = -1;
638 int nItem;
639 char letter;
641 switch (uMsg) {
642 case WM_COMMAND:
643 switch (LOWORD(wParam)) {
644 case IDC_LIST_DRIVES:
645 if (HIWORD(wParam) == LBN_DBLCLK) selection = -1;
646 if (HIWORD(wParam) == LBN_SELCHANGE) lastSel = SendDlgItemMessage(hDlg, IDC_LIST_DRIVES, LB_GETCURSEL, 0, 0);
647 break;
649 case IDC_BUTTON_ADD:
650 onAddDriveClicked(hDlg);
651 break;
653 case IDC_BUTTON_REMOVE:
654 if (HIWORD(wParam) != BN_CLICKED) break;
655 nItem = SendDlgItemMessage(hDlg, IDC_LIST_DRIVES, LB_GETCURSEL, 0, 0);
656 letter = SendDlgItemMessage(hDlg, IDC_LIST_DRIVES, LB_GETITEMDATA, nItem, 0);
657 removeDrive(letter);
658 refreshDriveDlg(driveDlgHandle);
659 break;
661 case IDC_BUTTON_EDIT:
662 if (HIWORD(wParam) != BN_CLICKED) break;
663 nItem = SendMessage(GetDlgItem(hDlg, IDC_LIST_DRIVES), LB_GETCURSEL, 0, 0);
664 letter = SendMessage(GetDlgItem(hDlg, IDC_LIST_DRIVES), LB_GETITEMDATA, nItem, 0);
665 DialogBoxParam(NULL, MAKEINTRESOURCE(IDD_DRIVE_EDIT), NULL, (DLGPROC) DriveEditDlgProc, (LPARAM) letter);
666 break;
668 case IDC_BUTTON_AUTODETECT:
669 WRITEME(hDlg);
670 break;
672 break;
674 case WM_NOTIFY: switch(((LPNMHDR)lParam)->code) {
675 case PSN_KILLACTIVE:
676 SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);
677 break;
678 case PSN_APPLY:
679 SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_NOERROR);
680 break;
681 case PSN_SETACTIVE:
682 driveDlgHandle = hDlg;
683 refreshDriveDlg (driveDlgHandle);
684 break;
686 break;
690 return FALSE;