ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/VTBFileUtil2/DiscBrowse.cxx
Revision: 368
Committed: 2008-08-23T02:44:00-07:00 (13 years, 10 months ago) by douglas
File size: 21419 byte(s)
Log Message:
Rearranged everything else.

File Contents

# User Rev Content
1 douglas 260 // Vance Thrift and Biller File Utility 2
2     //
3     // Douglas Thrift
4     //
5 douglas 295 // $Id: DiscBrowse.cxx,v 1.12 2003/09/12 04:26:54 douglas Exp $
6 douglas 260
7     #include "DiscBrowse.h"
8 douglas 265
9 douglas 282 DiscBrowse::DiscBrowse()
10     {
11     number = count++;
12    
13     browsers.insert(pair<unsigned, DiscBrowse*>(number, this));
14    
15     title = programName + " - Disc Browse";
16     popup = CreatePopupMenu();
17    
18     MENUITEMINFO open, separator, properties;
19    
20     open.cbSize = sizeof(open);
21     open.fMask = MIIM_ID | MIIM_STATE | MIIM_TYPE;
22     open.fType = MFT_STRING;
23     open.fState = MFS_DEFAULT;
24     open.wID = 1;
25     open.dwTypeData = "&Open";
26     open.cch = 5;
27     separator.cbSize = sizeof(open);
28     separator.fMask = MIIM_TYPE;
29     separator.fType = MFT_SEPARATOR;
30     properties.cbSize = sizeof(open);
31     properties.fMask = MIIM_ID | MIIM_TYPE;
32     properties.fType = MFT_STRING;
33     properties.wID = 2;
34     properties.dwTypeData = "P&roperties";
35     properties.cch = 11;
36    
37     InsertMenuItem(popup, 0, TRUE, &open);
38     InsertMenuItem(popup, 1, TRUE, &separator);
39     InsertMenuItem(popup, 2, TRUE, &properties);
40    
41     // start
42     wizard[0].dwSize = sizeof(wizard[0]);
43     wizard[0].dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USEHEADERTITLE |
44     PSP_USEHEADERSUBTITLE;
45     wizard[0].hInstance = gui.instance;
46     wizard[0].pszTemplate = MAKEINTRESOURCE(IDD_BEGIN);
47     wizard[0].pszTitle = title.c_str();
48     wizard[0].pfnDlgProc = start;
49     wizard[0].lParam = number;
50     wizard[0].pszHeaderTitle = "Start";
51     wizard[0].pszHeaderSubTitle = "Change any settings before browsing.";
52    
53     // browse
54     wizard[1].dwSize = sizeof(wizard[1]);
55     wizard[1].dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USEHEADERTITLE |
56     PSP_USEHEADERSUBTITLE;
57     wizard[1].hInstance = gui.instance;
58     wizard[1].pszTemplate = MAKEINTRESOURCE(IDD_BROWSE);
59     wizard[1].pszTitle = title.c_str();
60     wizard[1].pfnDlgProc = browse;
61     wizard[1].lParam = number;
62     wizard[1].pszHeaderTitle = "Browse";
63     wizard[1].pszHeaderSubTitle = "View documents on the disc.";
64     }
65    
66     DiscBrowse::~DiscBrowse()
67     {
68     DestroyMenu(popup);
69     browsers.erase(number);
70     }
71    
72 douglas 265 void DiscBrowse::run(void)
73     {
74 douglas 282 loadDir();
75    
76     PROPSHEETHEADER header;
77    
78     // header
79     header.dwSize = sizeof(header);
80     header.dwFlags = PSH_DEFAULT | PSH_HEADER | PSH_PROPSHEETPAGE |
81     PSH_USEICONID | PSH_WIZARD97 | PSH_WIZARDHASFINISH;
82     header.hwndParent = NULL;
83     header.hInstance = gui.instance;
84     header.pszIcon = MAKEINTRESOURCE(IDI_VTB_ICON);
85     header.nPages = 2;
86     header.nStartPage = 0;
87     header.ppsp = wizard;
88     header.pszbmHeader = MAKEINTRESOURCE(IDB_VTB_BMP);
89    
90     PropertySheet(&header);
91     saveDir();
92 douglas 265 }
93 douglas 282
94     unsigned DiscBrowse::count = 0;
95     map<unsigned, DiscBrowse*> DiscBrowse::browsers;
96    
97     map<HWND, DiscBrowse*> DiscBrowse::windows;
98    
99     void DiscBrowse::loadDir(void)
100     {
101 douglas 283 HKEY key;
102    
103     if (RegOpenKeyEx(HKEY_CURRENT_USER,
104     "Software\\DouglasThrift\\VTBFileUtil2", 0, KEY_QUERY_VALUE, &key) ==
105     ERROR_SUCCESS)
106     {
107     DWORD type;
108     char data[MAX_PATH];
109     DWORD size = MAX_PATH;
110    
111     if (RegQueryValueEx(key, "DiscDir", NULL, &type, LPBYTE(data), &size)
112     == ERROR_SUCCESS)
113     {
114     data[size - 1] = '\0';
115    
116     switch (type)
117     {
118     case REG_EXPAND_SZ:
119     {
120     char folder[MAX_PATH];
121    
122     ExpandEnvironmentStrings(data, folder, MAX_PATH);
123    
124 douglas 288 discDir = tail(folder);
125 douglas 283 }
126     break;
127     case REG_SZ:
128 douglas 288 discDir = tail(data);
129 douglas 283 break;
130     default:
131     setDiscDir();
132     break;
133     }
134     }
135     else
136     {
137     setDiscDir();
138     }
139    
140     RegCloseKey(key);
141     }
142     else
143     {
144     setDiscDir();
145     }
146    
147     if (debug) cerr << "discDir = " << discDir << "\n";
148 douglas 282 }
149    
150     void DiscBrowse::saveDir(void)
151     {
152 douglas 283 HKEY key;
153    
154 douglas 291 if (LONG code = RegCreateKeyEx(HKEY_CURRENT_USER,
155 douglas 283 "Software\\DouglasThrift\\VTBFileUtil2", 0, NULL,
156     REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE | KEY_SET_VALUE, NULL, &key,
157     NULL) == ERROR_SUCCESS)
158     {
159     DWORD type;
160     char data[MAX_PATH];
161     DWORD size = MAX_PATH;
162    
163     if (RegQueryValueEx(key, "DiscDir", NULL, &type, LPBYTE(data), &size)
164     == ERROR_SUCCESS)
165     {
166     data[size - 1] = '\0';
167     }
168     else
169     {
170     data[0] = '\0';
171     }
172    
173     if (discDir != data || type != REG_SZ)
174     {
175 douglas 291 if (code = RegSetValueEx(key, "DiscDir", 0, REG_SZ,
176 douglas 283 LPBYTE(discDir.c_str()), discDir.length() + 1) !=
177     ERROR_SUCCESS)
178     {
179 douglas 291 error(NULL, code);
180 douglas 283 }
181     }
182    
183     RegCloseKey(key);
184     }
185     else
186     {
187 douglas 291 error(NULL, code);
188 douglas 283 }
189 douglas 282 }
190    
191     void DiscBrowse::setDiscDir(HWND parent)
192     {
193 douglas 292 char buffer[MAX_PATH];
194    
195     SHGetFolderPath(parent, CSIDL_FLAG_CREATE | CSIDL_DESKTOPDIRECTORY, NULL,
196     0, buffer);
197    
198 douglas 283 BROWSEINFO info;
199    
200     info.hwndOwner = parent;
201     info.pidlRoot = NULL;
202     info.pszDisplayName = NULL;
203     info.lpszTitle = "Select the Disc";
204     info.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
205     info.lpfn = browse;
206     info.lParam = MAKELPARAM(number, true);
207     info.iImage = 0;
208    
209     do
210     {
211     LPITEMIDLIST id = SHBrowseForFolder(&info);
212    
213     if (id != NULL)
214     {
215     char folder[MAX_PATH];
216    
217 douglas 288 if (SHGetPathFromIDList(id, folder)) discDir = tail(folder);
218 douglas 283
219 douglas 290 LPMALLOC destruct;
220 douglas 283
221 douglas 290 SHGetMalloc(&destruct);
222     destruct->Free(id);
223     destruct->Release();
224     }
225 douglas 283
226     if (discDir == "")
227     {
228     switch (MessageBox(parent, "Disc needs to be selected.",
229     title.c_str(), MB_ABORTRETRYIGNORE | MB_ICONERROR))
230     {
231     case IDABORT:
232     exit(1);
233     break;
234     case IDRETRY:
235     break;
236     case IDIGNORE:
237     Beep(2200, 250);
238     Beep(1100, 500);
239     Beep(3300, 250);
240     exit(2);
241     break;
242     }
243     }
244     }
245     while (discDir == "");
246    
247     if (debug) cerr << "discDir = " << discDir << "\n";
248 douglas 282 }
249    
250 douglas 284 void DiscBrowse::populate(HWND parent)
251     {
252     set<IndividualClient> clients;
253    
254     do
255     {
256 douglas 288 string client = discDir + "*_*." + IndividualClient::getExtension();
257 douglas 284 WIN32_FIND_DATA found;
258     HANDLE finder = FindFirstFile(client.c_str(), &found);
259    
260     if (finder != INVALID_HANDLE_VALUE)
261     {
262     do
263     {
264     clients.insert(IndividualClient(found.cFileName));
265     }
266     while (FindNextFile(finder, &found));
267    
268     FindClose(finder);
269     }
270    
271     if (clients.empty())
272     {
273     if (MessageBox(parent, "No client documents found.",
274     title.c_str(), MB_RETRYCANCEL | MB_ICONQUESTION) == IDCANCEL)
275     break;
276     }
277     }
278     while (clients.empty());
279    
280 douglas 293 if (clients.empty())
281 douglas 284 {
282 douglas 293 PropSheet_PressButton(GetParent(parent), PSBTN_BACK);
283     }
284     else
285     {
286 douglas 285 SHFILEINFO info;
287     HIMAGELIST icons =
288     HIMAGELIST(SHGetFileInfo((*clients.begin()).getFile().c_str(),
289     0, &info, sizeof(info), SHGFI_SMALLICON | SHGFI_SYSICONINDEX));
290    
291     ListView_SetImageList(GetDlgItem(parent, IDC_BROWSE_DISC), icons,
292     LVSIL_SMALL);
293    
294 douglas 284 if (debug) cerr << "clients = {\n";
295    
296     for (set<IndividualClient>::iterator itor = clients.begin(); itor !=
297     clients.end(); itor++)
298     {
299     IndividualClient client = *itor;
300    
301     if (debug) cerr << " {\n"
302     << " number = " << client.getNumber() << "\n"
303     << " name = " << client.getName() << "\n"
304     << " file = " << client.getFile() << "\n"
305     << " }\n";
306 douglas 285
307     char clientFile[MAX_PATH], clientNumber[MAX_PATH],
308     clientName[MAX_PATH], clientSize[MAX_PATH];
309     HANDLE fileSize = CreateFile(client.getFile().c_str(),
310     GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
311     FILE_ATTRIBUTE_NORMAL, NULL);
312     DWORD bytes = GetFileSize(fileSize, NULL);
313    
314     CloseHandle(fileSize);
315 douglas 295 StringCchPrintf(clientFile, MAX_PATH, "%s",
316     client.getFile().c_str());
317     StringCchPrintf(clientNumber, MAX_PATH, "%u", client.getNumber());
318     StringCchPrintf(clientName, MAX_PATH, "%s",
319     client.getName().c_str());
320     StringCchPrintf(clientSize, MAX_PATH, "%.2f MB", FLOAT(bytes) /
321     FLOAT(1024 * 1024));
322 douglas 285
323     LVITEM number, name, file, size;
324    
325     file.mask = LVIF_IMAGE | LVIF_PARAM | LVIF_TEXT;
326     file.iItem = 0;
327     file.iSubItem = 0;
328     file.pszText = clientFile;
329     file.iImage = info.iIcon;
330     file.lParam = bytes;
331    
332     int item = ListView_InsertItem(GetDlgItem(parent, IDC_BROWSE_DISC),
333     &file);
334    
335     number.mask = LVIF_TEXT;
336     number.iItem = item;
337     number.iSubItem = 1;
338     number.pszText = clientNumber;
339     name.mask = LVIF_TEXT;
340     name.iItem = item;
341     name.iSubItem = 2;
342     name.pszText = clientName;
343     size.mask = LVIF_TEXT;
344     size.iItem = item;
345     size.iSubItem = 3;
346     size.pszText = clientSize;
347    
348     ListView_SetItem(GetDlgItem(parent, IDC_BROWSE_DISC), &number);
349     ListView_SetItem(GetDlgItem(parent, IDC_BROWSE_DISC), &name);
350     ListView_SetItem(GetDlgItem(parent, IDC_BROWSE_DISC), &size);
351 douglas 284 }
352    
353     if (debug) cerr << "}\n";
354 douglas 285
355     Thing thing;
356    
357     sortFile = true, sortNumber = true, sortName = true, sortSize = true;
358     thing.index = 1;
359     thing.order = sortNumber;
360     thing.list = GetDlgItem(parent, IDC_BROWSE_DISC);
361     sortNumber = !sortNumber;
362    
363     ListView_SortItemsEx(thing.list, sort, &thing);
364 douglas 284 }
365     }
366    
367 douglas 282 DiscBrowse* DiscBrowse::which(HWND window)
368     {
369     map<HWND, DiscBrowse*>::iterator itor = windows.find(window);
370    
371     return itor->second;
372     }
373    
374     DiscBrowse* DiscBrowse::which(HWND window, LPARAM l)
375     {
376     LPPROPSHEETPAGE page = LPPROPSHEETPAGE(l);
377     map<unsigned, DiscBrowse*>::iterator itor = browsers.find(page->lParam);
378    
379     windows.insert(pair<HWND, DiscBrowse*>(window, itor->second));
380    
381     return itor->second;
382     }
383    
384     int DiscBrowse::browse(HWND dialog, UINT msg, LPARAM l, LPARAM d)
385     {
386     map<unsigned, DiscBrowse*>::iterator itor = browsers.find(LOWORD(d));
387     DiscBrowse* data = itor->second;
388    
389     switch (msg)
390     {
391     case BFFM_INITIALIZED:
392     center(dialog);
393     SendMessage(dialog, BFFM_SETOKTEXT, 0,
394     LPARAM(toWide("&Select").c_str()));
395     SendMessage(dialog, BFFM_SETEXPANDED, FALSE, CSIDL_DRIVES);
396 douglas 290
397     if (data->discDir != "")
398     {
399     IShellFolder* desktop;
400     LPWSTR path = new WCHAR[data->discDir.length() + 1];
401     LPITEMIDLIST id;
402    
403 douglas 295 StringCchPrintfW(path, data->discDir.length() + 1, L"%s",
404     toWide(data->discDir).c_str());
405 douglas 290
406     if (debug) cerr << "path = " << toAnsi(path) << "\n";
407    
408     SHGetDesktopFolder(&desktop);
409     desktop->ParseDisplayName(dialog, NULL, path, NULL, &id, NULL);
410    
411     if (id != NULL)
412     {
413     SendMessage(dialog, BFFM_SETSELECTION, FALSE, LPARAM(id));
414    
415     LPMALLOC destruct;
416    
417     SHGetMalloc(&destruct);
418     destruct->Free(id);
419     destruct->Release();
420     }
421    
422     desktop->Release();
423     }
424 douglas 282 break;
425     case BFFM_SELCHANGED:
426     {
427 douglas 284 SHFILEINFO info;
428 douglas 282
429 douglas 284 SHGetFileInfo(LPCSTR(l), 0, &info, sizeof(info), SHGFI_DISPLAYNAME
430     | SHGFI_PIDL);
431     SendMessage(dialog, BFFM_SETSTATUSTEXT, 0,
432     LPARAM(info.szDisplayName));
433 douglas 282
434 douglas 284 char folder[MAX_PATH];
435 douglas 282
436 douglas 284 if (!SHGetPathFromIDList(LPCITEMIDLIST(l), folder))
437 douglas 282 {
438     SendMessage(dialog, BFFM_ENABLEOK, 0, 0);
439     }
440     }
441     break;
442     }
443    
444     return 0;
445     }
446    
447 douglas 285 int DiscBrowse::sort(LPARAM first, LPARAM second, LPARAM l)
448     {
449     Thing* thing = (Thing*)(l);
450    
451     switch (thing->index)
452     {
453     case 0:
454     {
455     char one[MAX_PATH], two[MAX_PATH];
456    
457     ListView_GetItemText(thing->list, first, 0, one, MAX_PATH);
458     ListView_GetItemText(thing->list, second, 0, two, MAX_PATH);
459    
460     string first = one, second = two;
461    
462     if (first < second)
463     {
464     return thing->order ? -1 : 1;
465     }
466     else if (first > second)
467     {
468     return thing->order ? 1 : -1;
469     }
470     }
471     break;
472     case 1:
473     {
474     char one[MAX_PATH], two[MAX_PATH];
475    
476     ListView_GetItemText(thing->list, first, 0, one, MAX_PATH);
477     ListView_GetItemText(thing->list, second, 0, two, MAX_PATH);
478    
479     IndividualClient first(one), second(two);
480    
481     if (first < second)
482     {
483     return thing->order ? -1 : 1;
484     }
485     else if (first > second)
486     {
487     return thing->order ? 1 : -1;
488     }
489     }
490     break;
491     case 2:
492     {
493     char one[MAX_PATH], two[MAX_PATH];
494    
495     ListView_GetItemText(thing->list, first, 2, one, MAX_PATH);
496     ListView_GetItemText(thing->list, second, 2, two, MAX_PATH);
497    
498     if (mcLess(one, two))
499     {
500     return thing->order ? -1 : 1;
501     }
502     else if (mcGreater(one, two))
503     {
504     return thing->order ? 1 : -1;
505     }
506     }
507     break;
508     case 3:
509     if (first < second)
510     {
511     return thing->order ? -1 : 1;
512     }
513     else if (first > second)
514     {
515     return thing->order ? 1 : -1;
516     }
517     break;
518     }
519    
520     return 0;
521     }
522    
523 douglas 282 INT_PTR DiscBrowse::start(HWND dialog, UINT msg, WPARAM w, LPARAM l)
524     {
525     DiscBrowse* data = which(dialog);
526    
527     switch (msg)
528     {
529     case WM_INITDIALOG:
530     center(GetParent(dialog));
531     SendMessage(GetParent(dialog), WM_SETICON, ICON_BIG, LPARAM(gui.icon));
532    
533     data = which(dialog, l);
534     break;
535     case WM_NOTIFY:
536     {
537     LPNMHDR nm = LPNMHDR(l);
538    
539     switch (nm->code)
540     {
541     case PSN_SETACTIVE:
542     PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_FINISH |
543     PSWIZB_NEXT);
544 douglas 283
545     {
546     SHFILEINFO info;
547    
548     SHGetFileInfo(data->discDir.c_str(), 0, &info,
549     sizeof(info), SHGFI_ICONLOCATION);
550    
551 douglas 284 HICON icon = ExtractIcon(gui.instance, info.szDisplayName,
552     info.iIcon);
553 douglas 283
554     SendDlgItemMessage(dialog, IDC_BEGIN_ICON, STM_SETIMAGE,
555     IMAGE_ICON, LPARAM(icon));
556     }
557    
558     {
559 douglas 284 SHFILEINFO info;
560 douglas 283
561 douglas 284 SHGetFileInfo(data->discDir.c_str(), 0, &info,
562     sizeof(info), SHGFI_DISPLAYNAME);
563    
564     SetDlgItemText(dialog, IDC_BEGIN_TEXT, info.szDisplayName);
565 douglas 283 }
566 douglas 282 break;
567 douglas 284 case PSN_WIZNEXT:
568     SetCurrentDirectory(data->discDir.c_str());
569     break;
570 douglas 282 }
571     }
572     break;
573 douglas 283 case WM_COMMAND:
574     switch (LOWORD(w))
575     {
576     case IDC_BEGIN_BROWSE:
577     data->setDiscDir(dialog);
578    
579     {
580     SHFILEINFO info;
581    
582     SHGetFileInfo(data->discDir.c_str(), 0, &info, sizeof(info),
583     SHGFI_ICONLOCATION);
584    
585 douglas 284 HICON icon = ExtractIcon(gui.instance, info.szDisplayName,
586     info.iIcon);
587 douglas 283
588     SendDlgItemMessage(dialog, IDC_BEGIN_ICON, STM_SETIMAGE,
589     IMAGE_ICON, LPARAM(icon));
590     }
591    
592     {
593 douglas 284 SHFILEINFO info;
594 douglas 283
595 douglas 284 SHGetFileInfo(data->discDir.c_str(), 0, &info,
596     sizeof(info), SHGFI_DISPLAYNAME);
597    
598     SetDlgItemText(dialog, IDC_BEGIN_TEXT, info.szDisplayName);
599 douglas 283 }
600     break;
601     }
602 douglas 282 }
603    
604     return FALSE;
605     }
606    
607     INT_PTR DiscBrowse::browse(HWND dialog, UINT msg, WPARAM w, LPARAM l)
608     {
609     DiscBrowse* data = which(dialog);
610 douglas 290 int previous = -1;
611 douglas 282
612     switch (msg)
613     {
614     case WM_INITDIALOG:
615     data = which(dialog, l);
616    
617 douglas 285 ListView_SetExtendedListViewStyleEx(GetDlgItem(dialog,
618     IDC_BROWSE_DISC), LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP |
619     LVS_EX_LABELTIP, LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP |
620     LVS_EX_LABELTIP);
621    
622 douglas 282 {
623 douglas 285 LVCOLUMN file, number, name, size;
624 douglas 282
625 douglas 285 file.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
626     file.fmt = LVCFMT_IMAGE;
627     file.cx = 224;
628     file.pszText = "File Name";
629 douglas 283 number.mask = LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
630 douglas 284 number.cx = 56;
631 douglas 282 number.pszText = "Number";
632 douglas 285 number.iSubItem = 1;
633 douglas 282 name.mask = LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
634 douglas 285 name.cx = 152;
635 douglas 282 name.pszText = "Client Name";
636 douglas 285 name.iSubItem = 2;
637 douglas 283 size.mask = LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
638 douglas 284 size.cx = 68;
639 douglas 283 size.pszText = "Size";
640     size.iSubItem = 3;
641 douglas 282
642     ListView_InsertColumn(GetDlgItem(dialog, IDC_BROWSE_DISC), 0,
643 douglas 283 &file);
644 douglas 285 ListView_InsertColumn(GetDlgItem(dialog, IDC_BROWSE_DISC), 1,
645 douglas 282 &number);
646 douglas 285 ListView_InsertColumn(GetDlgItem(dialog, IDC_BROWSE_DISC), 2,
647 douglas 282 &name);
648 douglas 283 ListView_InsertColumn(GetDlgItem(dialog, IDC_BROWSE_DISC), 3,
649     &size);
650 douglas 282 }
651 douglas 290
652     {
653     int columns[4];
654    
655     columns[0] = 1;
656     columns[1] = 2;
657     columns[2] = 0;
658     columns[3] = 3;
659    
660     ListView_SetColumnOrderArray(GetDlgItem(dialog, IDC_BROWSE_DISC),
661     4, columns);
662     }
663 douglas 282 break;
664     case WM_NOTIFY:
665     if (w == IDC_BROWSE_DISC)
666     {
667     LPNMITEMACTIVATE ni = LPNMITEMACTIVATE(l);
668    
669     switch (ni->hdr.code)
670     {
671 douglas 285 case LVN_COLUMNCLICK:
672     {
673     Thing thing;
674    
675     thing.index = ni->iSubItem;
676    
677     switch (thing.index)
678     {
679     case 0:
680     thing.order = data->sortFile;
681     data->sortFile = !data->sortFile;
682     break;
683     case 1:
684     thing.order = data->sortNumber;
685     data->sortNumber = !data->sortNumber;
686     break;
687     case 2:
688     thing.order = data->sortName;
689     data->sortName = !data->sortName;
690     break;
691     case 3:
692     thing.order = data->sortSize;
693     data->sortSize = !data->sortSize;
694     break;
695     }
696    
697     thing.list = GetDlgItem(dialog, IDC_BROWSE_DISC);
698    
699     if (ni->iSubItem == 3)
700     {
701     ListView_SortItems(thing.list, sort, &thing);
702     }
703     else
704     {
705     ListView_SortItemsEx(thing.list, sort, &thing);
706     }
707     }
708     break;
709 douglas 290 case LVN_ITEMCHANGED:
710     if (ListView_GetNextItem(GetDlgItem(dialog, IDC_BROWSE_DISC),
711     -1, LVNI_SELECTED) != -1)
712     {
713     EnableWindow(GetDlgItem(dialog, IDC_BROWSE_OPEN), TRUE);
714     EnableWindow(GetDlgItem(dialog, IDC_BROWSE_PROP), TRUE);
715     }
716     else
717     {
718     EnableWindow(GetDlgItem(dialog, IDC_BROWSE_OPEN), FALSE);
719     EnableWindow(GetDlgItem(dialog, IDC_BROWSE_PROP), FALSE);
720     }
721     break;
722 douglas 282 case NM_DBLCLK:
723 douglas 284 if (ni->iItem != -1)
724     {
725 douglas 290 char scan[MAX_PATH];
726    
727     ListView_GetItemText(GetDlgItem(dialog, IDC_BROWSE_DISC),
728     ni->iItem, 0, scan, MAX_PATH);
729     ShellExecute(dialog, NULL, scan, NULL, NULL,
730     SW_SHOWDEFAULT);
731 douglas 284 }
732 douglas 282 break;
733     }
734     }
735     else
736     {
737     LPNMHDR nm = LPNMHDR(l);
738    
739     switch (nm->code)
740     {
741     case PSN_SETACTIVE:
742     PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
743     PSWIZB_FINISH);
744 douglas 284 data->populate(dialog);
745    
746     {
747     SHFILEINFO info;
748    
749     SHGetFileInfo(data->discDir.c_str(), 0, &info,
750     sizeof(info), SHGFI_ICONLOCATION);
751    
752     HICON icon = ExtractIcon(gui.instance, info.szDisplayName,
753     info.iIcon);
754    
755     SendDlgItemMessage(dialog, IDC_BROWSE_ICON, STM_SETIMAGE,
756     IMAGE_ICON, LPARAM(icon));
757     }
758    
759     {
760     SHFILEINFO info;
761    
762     SHGetFileInfo(data->discDir.c_str(), 0, &info,
763     sizeof(info), SHGFI_DISPLAYNAME);
764    
765     SetDlgItemText(dialog, IDC_BROWSE_TEXT,
766     info.szDisplayName);
767     }
768 douglas 282 break;
769 douglas 284 case PSN_WIZBACK:
770 douglas 290 EnableWindow(GetDlgItem(dialog, IDC_BROWSE_OPEN), FALSE);
771     EnableWindow(GetDlgItem(dialog, IDC_BROWSE_PROP), FALSE);
772 douglas 284 ListView_DeleteAllItems(GetDlgItem(dialog, IDC_BROWSE_DISC));
773     break;
774 douglas 282 }
775     }
776     break;
777 douglas 290 case WM_COMMAND:
778     switch (LOWORD(w))
779     {
780     case IDC_BROWSE_REFRESH:
781     EnableWindow(GetDlgItem(dialog, IDC_BROWSE_OPEN), FALSE);
782     EnableWindow(GetDlgItem(dialog, IDC_BROWSE_PROP), FALSE);
783     ListView_DeleteAllItems(GetDlgItem(dialog, IDC_BROWSE_DISC));
784     data->populate(dialog);
785 douglas 293
786     {
787     SHFILEINFO info;
788    
789     SHGetFileInfo(data->discDir.c_str(), 0, &info, sizeof(info),
790     SHGFI_ICONLOCATION);
791    
792     HICON icon = ExtractIcon(gui.instance, info.szDisplayName,
793     info.iIcon);
794    
795     SendDlgItemMessage(dialog, IDC_BROWSE_ICON, STM_SETIMAGE,
796     IMAGE_ICON, LPARAM(icon));
797     }
798    
799     {
800     SHFILEINFO info;
801    
802     SHGetFileInfo(data->discDir.c_str(), 0, &info, sizeof(info),
803     SHGFI_DISPLAYNAME);
804    
805     SetDlgItemText(dialog, IDC_BROWSE_TEXT, info.szDisplayName);
806     }
807 douglas 290 break;
808     case IDC_BROWSE_OPEN:
809     do
810     {
811     char scan[MAX_PATH];
812     int index = ListView_GetNextItem(GetDlgItem(dialog,
813     IDC_BROWSE_DISC), previous, LVNI_SELECTED);
814    
815     previous = index;
816    
817     if (previous == -1) continue;
818    
819     ListView_GetItemText(GetDlgItem(dialog, IDC_BROWSE_DISC),
820     index, 0, scan, MAX_PATH);
821     ShellExecute(dialog, NULL, scan, NULL, NULL, SW_SHOWDEFAULT);
822     }
823     while (previous != -1);
824     break;
825     case IDC_BROWSE_PROP:
826     do
827     {
828     char scan[MAX_PATH];
829     int index = ListView_GetNextItem(GetDlgItem(dialog,
830     IDC_BROWSE_DISC), previous, LVNI_SELECTED);
831    
832     previous = index;
833    
834     if (previous == -1) continue;
835    
836     ListView_GetItemText(GetDlgItem(dialog, IDC_BROWSE_DISC),
837     index, 0, scan, MAX_PATH);
838    
839     SHELLEXECUTEINFO info;
840    
841     info.cbSize = sizeof(info);
842     info.fMask = SEE_MASK_INVOKEIDLIST;
843     info.hwnd = dialog;
844     info.lpVerb = "properties";
845     info.lpFile = scan;
846     info.lpParameters = NULL;
847     info.lpDirectory = NULL;
848     info.nShow = SW_SHOWDEFAULT;
849     info.lpIDList = NULL;
850    
851     ShellExecuteEx(&info);
852     }
853     while (previous != -1);
854     break;
855     }
856     break;
857     case WM_CONTEXTMENU:
858     if (ListView_GetNextItem(GetDlgItem(dialog, IDC_BROWSE_DISC), -1,
859     LVNI_SELECTED) != -1)
860     {
861     POINT spot;
862     LVHITTESTINFO test;
863    
864     test.pt.x = GET_X_LPARAM(l);
865     test.pt.y = GET_Y_LPARAM(l);
866    
867     ScreenToClient(GetDlgItem(dialog, IDC_BROWSE_DISC), &test.pt);
868     ListView_HitTest(GetDlgItem(dialog, IDC_BROWSE_DISC), &test);
869    
870     if (test.iItem != -1)
871     {
872     spot.x = test.pt.x;
873     spot.y = test.pt.y;
874     }
875     else if (GET_X_LPARAM(l) == -1 && GET_Y_LPARAM(l) == -1)
876     {
877     int index = ListView_GetNextItem(GetDlgItem(dialog,
878     IDC_BROWSE_DISC), -1, LVNI_SELECTED);
879     RECT rect;
880    
881     ListView_EnsureVisible(GetDlgItem(dialog, IDC_BROWSE_DISC),
882     index, FALSE);
883     ListView_GetItemRect(GetDlgItem(dialog, IDC_BROWSE_DISC),
884     index, &rect, LVIR_SELECTBOUNDS);
885    
886     spot.x = rect.left;
887     spot.y = rect.top;
888     }
889    
890     ClientToScreen(GetDlgItem(dialog, IDC_BROWSE_DISC), &spot);
891    
892     int code = TrackPopupMenuEx(data->popup, TPM_LEFTALIGN |
893     TPM_TOPALIGN | TPM_NONOTIFY | TPM_RETURNCMD | TPM_RIGHTBUTTON,
894     spot.x, spot.y, GetDlgItem(dialog, IDC_BROWSE_DISC), NULL);
895    
896     switch (code)
897     {
898     case 1:
899     do
900     {
901     char scan[MAX_PATH];
902     int index = ListView_GetNextItem(GetDlgItem(dialog,
903     IDC_BROWSE_DISC), previous, LVNI_SELECTED);
904    
905     previous = index;
906    
907     if (previous == -1) continue;
908    
909     ListView_GetItemText(GetDlgItem(dialog, IDC_BROWSE_DISC),
910     index, 0, scan, MAX_PATH);
911     ShellExecute(dialog, NULL, scan, NULL, NULL,
912     SW_SHOWDEFAULT);
913     }
914     while (previous != -1);
915     break;
916     case 2:
917     do
918     {
919     char scan[MAX_PATH];
920     int index = ListView_GetNextItem(GetDlgItem(dialog,
921     IDC_BROWSE_DISC), previous, LVNI_SELECTED);
922    
923     previous = index;
924    
925     if (previous == -1) continue;
926    
927     ListView_GetItemText(GetDlgItem(dialog, IDC_BROWSE_DISC),
928     index, 0, scan, MAX_PATH);
929    
930     SHELLEXECUTEINFO info;
931    
932     info.cbSize = sizeof(info);
933     info.fMask = SEE_MASK_INVOKEIDLIST;
934     info.hwnd = dialog;
935     info.lpVerb = "properties";
936     info.lpFile = scan;
937     info.lpParameters = NULL;
938     info.lpDirectory = NULL;
939     info.nShow = SW_SHOWDEFAULT;
940     info.lpIDList = NULL;
941    
942     ShellExecuteEx(&info);
943     }
944     while (previous != -1);
945     break;
946     }
947     }
948     break;
949 douglas 282 }
950    
951     return FALSE;
952     }