2 |
|
// |
3 |
|
// Douglas Thrift |
4 |
|
// |
5 |
< |
// $Id: ScanUtility.cxx,v 1.6 2003/08/21 06:29:24 douglas Exp $ |
5 |
> |
// $Id: ScanUtility.cxx,v 1.8 2003/08/24 07:31:45 douglas Exp $ |
6 |
|
|
7 |
|
#include "ScanUtility.h" |
8 |
|
|
14 |
|
|
15 |
|
sprintf(title, "%s - Scan Utility", programName.c_str()); |
16 |
|
loadDirs(); |
17 |
+ |
|
18 |
+ |
popup = CreatePopupMenu(); |
19 |
+ |
|
20 |
+ |
MENUITEMINFO open, separator, properties; |
21 |
+ |
|
22 |
+ |
open.cbSize = sizeof(open); |
23 |
+ |
open.fMask = MIIM_ID | MIIM_STATE | MIIM_TYPE; |
24 |
+ |
open.fType = MFT_STRING; |
25 |
+ |
open.fState = MFS_DEFAULT; |
26 |
+ |
open.wID = 1; |
27 |
+ |
open.dwTypeData = "&Open"; |
28 |
+ |
open.cch = 5; |
29 |
+ |
separator.cbSize = sizeof(open); |
30 |
+ |
separator.fMask = MIIM_TYPE; |
31 |
+ |
separator.fType = MFT_SEPARATOR; |
32 |
+ |
properties.cbSize = sizeof(open); |
33 |
+ |
properties.fMask = MIIM_ID | MIIM_TYPE; |
34 |
+ |
properties.fType = MFT_STRING; |
35 |
+ |
properties.wID = 2; |
36 |
+ |
properties.dwTypeData = "P&roperties"; |
37 |
+ |
properties.cch = 11; |
38 |
+ |
|
39 |
+ |
InsertMenuItem(popup, 0, TRUE, &open); |
40 |
+ |
InsertMenuItem(popup, 1, TRUE, &separator); |
41 |
+ |
InsertMenuItem(popup, 2, TRUE, &properties); |
42 |
|
|
43 |
|
// start |
44 |
|
wizard[0].dwSize = sizeof(wizard[0]); |
65 |
|
wizard[1].lParam = number; |
66 |
|
wizard[1].pszHeaderTitle = "Select"; |
67 |
|
wizard[1].pszHeaderSubTitle = "Choose the scanned document to save."; |
68 |
+ |
|
69 |
+ |
// enter |
70 |
+ |
wizard[2].dwSize = sizeof(wizard[2]); |
71 |
+ |
wizard[2].dwFlags = PSP_DEFAULT | PSP_USEHICON | PSP_USETITLE | |
72 |
+ |
PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE; |
73 |
+ |
wizard[2].hInstance = gui.instance; |
74 |
+ |
wizard[2].pszTemplate = MAKEINTRESOURCE(IDD_ENTER); |
75 |
+ |
wizard[2].hIcon = gui.icon; |
76 |
+ |
wizard[2].pszTitle = title; |
77 |
+ |
wizard[2].pfnDlgProc = enter; |
78 |
+ |
wizard[2].lParam = number; |
79 |
+ |
wizard[2].pszHeaderTitle = "Enter"; |
80 |
+ |
wizard[2].pszHeaderSubTitle = "Input the client information."; |
81 |
|
} |
82 |
|
|
83 |
|
ScanUtility::~ScanUtility() |
84 |
|
{ |
85 |
+ |
DestroyMenu(popup); |
86 |
|
utilities.erase(number); |
87 |
|
saveDirs(); |
88 |
|
|
100 |
|
header.hwndParent = NULL; |
101 |
|
header.hInstance = gui.instance; |
102 |
|
header.pszIcon = MAKEINTRESOURCE(IDI_VTB_ICON); |
103 |
< |
header.nPages = 2; |
103 |
> |
header.nPages = 3; |
104 |
|
header.nStartPage = 0; |
105 |
|
header.ppsp = wizard; |
106 |
|
header.pszbmHeader = MAKEINTRESOURCE(IDB_VTB_BMP); |
417 |
|
ListView_SetImageList(GetDlgItem(parent, IDC_SELECT_SCANS), icons, |
418 |
|
LVSIL_SMALL); |
419 |
|
|
381 |
– |
int index = 0; |
382 |
– |
|
420 |
|
if (debug) cerr << "scans = {\n"; |
421 |
|
|
422 |
|
for (set<string>::iterator itor = scans.begin(); itor != scans.end(); |
431 |
|
LVITEM item; |
432 |
|
|
433 |
|
item.mask = LVIF_IMAGE | LVIF_TEXT; |
434 |
< |
item.iItem = index++; |
434 |
> |
item.iItem = 0; |
435 |
|
item.iSubItem = 0; |
399 |
– |
item.state = LVIS_SELECTED; |
400 |
– |
item.stateMask = LVIS_SELECTED; |
436 |
|
item.pszText = scan; |
437 |
|
item.iImage = info.iIcon; |
438 |
|
|
440 |
|
} |
441 |
|
|
442 |
|
if (debug) cerr << "}\n"; |
443 |
+ |
|
444 |
+ |
ListView_SetItemState(GetDlgItem(parent, IDC_SELECT_SCANS), 0, |
445 |
+ |
LVIS_SELECTED, LVIS_SELECTED); |
446 |
|
} |
447 |
|
} |
448 |
|
|
449 |
+ |
ScanUtility* ScanUtility::which(HWND window) |
450 |
+ |
{ |
451 |
+ |
map<HWND, ScanUtility*>::iterator itor = windows.find(window); |
452 |
+ |
|
453 |
+ |
return itor->second; |
454 |
+ |
} |
455 |
+ |
|
456 |
+ |
ScanUtility* ScanUtility::which(HWND window, LPARAM l) |
457 |
+ |
{ |
458 |
+ |
LPPROPSHEETPAGE page = LPPROPSHEETPAGE(l); |
459 |
+ |
map<unsigned, ScanUtility*>::iterator itor = utilities.find(page->lParam); |
460 |
+ |
|
461 |
+ |
windows.insert(pair<HWND, ScanUtility*>(window, itor->second)); |
462 |
+ |
|
463 |
+ |
return itor->second; |
464 |
+ |
} |
465 |
+ |
|
466 |
|
int ScanUtility::browse(HWND dialog, UINT msg, LPARAM l, LPARAM d) |
467 |
|
{ |
468 |
|
map<unsigned, ScanUtility*>::iterator itor = utilities.find(LOWORD(d)); |
508 |
|
|
509 |
|
INT_PTR ScanUtility::start(HWND dialog, UINT msg, WPARAM w, LPARAM l) |
510 |
|
{ |
511 |
< |
map<HWND, ScanUtility*>::iterator itor = windows.find(dialog); |
457 |
< |
ScanUtility* data = itor->second; |
511 |
> |
ScanUtility* data = which(dialog); |
512 |
|
|
513 |
|
switch (msg) |
514 |
|
{ |
515 |
|
case WM_INITDIALOG: |
516 |
|
center(GetParent(dialog)); |
517 |
< |
{ |
518 |
< |
LPPROPSHEETPAGE page = LPPROPSHEETPAGE(l); |
519 |
< |
map<unsigned, ScanUtility*>::iterator itor = |
466 |
< |
utilities.find(page->lParam); |
517 |
> |
SendMessage(GetParent(dialog), WM_SETICON, ICON_BIG, LPARAM(gui.icon)); |
518 |
> |
|
519 |
> |
data = which(dialog, l); |
520 |
|
|
468 |
– |
windows.insert(pair<HWND, ScanUtility*>(dialog, itor->second)); |
469 |
– |
} |
521 |
|
{ |
522 |
|
ostringstream instructions; |
523 |
|
|
524 |
< |
instructions << "1.\tIf you need instructions, you should not be r" |
525 |
< |
<< "unning this program\n\tin Scan Utility mode.\n" |
526 |
< |
<< "2.\tOtherwise, go forth and scan.\n" |
527 |
< |
<< "3.\tThen come back and click Next.\n"; |
524 |
> |
instructions << "1. If you need instructions, you should not be ru" |
525 |
> |
<< "nning this program in Scan Utility mode.\n" |
526 |
> |
<< "2. Otherwise, go forth and scan.\n" |
527 |
> |
<< "3. Then come back and click Next.\n"; |
528 |
|
|
529 |
|
SetDlgItemText(dialog, IDC_START_INSTRUCTIONS, |
530 |
|
instructions.str().c_str()); |
583 |
|
|
584 |
|
INT_PTR ScanUtility::select(HWND dialog, UINT msg, WPARAM w, LPARAM l) |
585 |
|
{ |
586 |
< |
map<HWND, ScanUtility*>::iterator itor = windows.find(dialog); |
536 |
< |
ScanUtility* data = itor->second; |
586 |
> |
ScanUtility* data = which(dialog); |
587 |
|
|
588 |
|
switch (msg) |
589 |
|
{ |
590 |
|
case WM_INITDIALOG: |
591 |
+ |
data = which(dialog, l); |
592 |
+ |
|
593 |
|
{ |
594 |
< |
LPPROPSHEETPAGE page = LPPROPSHEETPAGE(l); |
543 |
< |
map<unsigned, ScanUtility*>::iterator itor = |
544 |
< |
utilities.find(page->lParam); |
594 |
> |
ostringstream select; |
595 |
|
|
596 |
< |
windows.insert(pair<HWND, ScanUtility*>(dialog, itor->second)); |
596 |
> |
select << "Select the scanned document that you need to be save."; |
597 |
> |
|
598 |
> |
SetDlgItemText(dialog, IDC_SELECT_TEXT, select.str().c_str()); |
599 |
|
} |
600 |
+ |
|
601 |
|
{ |
602 |
|
LVCOLUMN column; |
603 |
|
|
613 |
|
case WM_NOTIFY: |
614 |
|
if (w == IDC_SELECT_SCANS) |
615 |
|
{ |
616 |
< |
switch (ListView_GetSelectedCount(GetDlgItem(dialog, |
617 |
< |
IDC_SELECT_SCANS))) |
616 |
> |
LPNMITEMACTIVATE ni = LPNMITEMACTIVATE(l); |
617 |
> |
|
618 |
> |
switch (ni->hdr.code) |
619 |
|
{ |
620 |
< |
case 1: |
621 |
< |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
622 |
< |
PSWIZB_NEXT); |
623 |
< |
break; |
624 |
< |
default: |
625 |
< |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK); |
620 |
> |
case NM_DBLCLK: |
621 |
> |
{ |
622 |
> |
char scan[MAX_PATH]; |
623 |
> |
|
624 |
> |
ListView_GetItemText(GetDlgItem(dialog, IDC_SELECT_SCANS), |
625 |
> |
ni->iItem, 0, scan, MAX_PATH); |
626 |
> |
ShellExecute(dialog, NULL, scan, NULL, NULL, |
627 |
> |
SW_SHOWDEFAULT); |
628 |
> |
} |
629 |
|
break; |
630 |
|
} |
631 |
|
} |
636 |
|
switch (nm->code) |
637 |
|
{ |
638 |
|
case PSN_SETACTIVE: |
639 |
< |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK); |
639 |
> |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
640 |
> |
PSWIZB_NEXT); |
641 |
|
data->populate(dialog); |
642 |
|
break; |
643 |
|
case PSN_WIZBACK: |
644 |
|
ListView_DeleteAllItems(GetDlgItem(dialog, IDC_SELECT_SCANS)); |
645 |
+ |
data->client.setFile(""); |
646 |
|
break; |
647 |
|
case PSN_WIZNEXT: |
648 |
< |
// |
648 |
> |
{ |
649 |
> |
int index = ListView_GetNextItem(GetDlgItem(dialog, |
650 |
> |
IDC_SELECT_SCANS), -1, LVNI_SELECTED); |
651 |
> |
char scan[MAX_PATH]; |
652 |
> |
|
653 |
> |
ListView_GetItemText(GetDlgItem(dialog, IDC_SELECT_SCANS), |
654 |
> |
index, 0, scan, MAX_PATH); |
655 |
> |
|
656 |
> |
data->scan = scan; |
657 |
> |
} |
658 |
> |
|
659 |
|
ListView_DeleteAllItems(GetDlgItem(dialog, IDC_SELECT_SCANS)); |
660 |
+ |
|
661 |
+ |
if (debug) cerr << "scan = " << data->scan << "\n"; |
662 |
+ |
break; |
663 |
+ |
} |
664 |
+ |
} |
665 |
+ |
break; |
666 |
+ |
case WM_CONTEXTMENU: |
667 |
+ |
{ |
668 |
+ |
char scan[MAX_PATH]; |
669 |
+ |
POINT spot; |
670 |
+ |
LVHITTESTINFO test; |
671 |
+ |
|
672 |
+ |
test.pt.x = GET_X_LPARAM(l); |
673 |
+ |
test.pt.y = GET_Y_LPARAM(l); |
674 |
+ |
|
675 |
+ |
ScreenToClient(GetDlgItem(dialog, IDC_SELECT_SCANS), &test.pt); |
676 |
+ |
ListView_HitTest(GetDlgItem(dialog, IDC_SELECT_SCANS), &test); |
677 |
+ |
|
678 |
+ |
if (test.iItem != -1) |
679 |
+ |
{ |
680 |
+ |
ListView_GetItemText(GetDlgItem(dialog, IDC_SELECT_SCANS), |
681 |
+ |
test.iItem, 0, scan, MAX_PATH); |
682 |
+ |
|
683 |
+ |
spot.x = test.pt.x; |
684 |
+ |
spot.y = test.pt.y; |
685 |
+ |
} |
686 |
+ |
else if (GET_X_LPARAM(l) == -1 && GET_Y_LPARAM(l) == -1) |
687 |
+ |
{ |
688 |
+ |
int index = ListView_GetNextItem(GetDlgItem(dialog, |
689 |
+ |
IDC_SELECT_SCANS), -1, LVNI_SELECTED); |
690 |
+ |
RECT rect; |
691 |
+ |
|
692 |
+ |
ListView_GetItemText(GetDlgItem(dialog, IDC_SELECT_SCANS), |
693 |
+ |
index, 0, scan, MAX_PATH); |
694 |
+ |
ListView_EnsureVisible(GetDlgItem(dialog, IDC_SELECT_SCANS), |
695 |
+ |
index, FALSE); |
696 |
+ |
ListView_GetItemRect(GetDlgItem(dialog, IDC_SELECT_SCANS), |
697 |
+ |
index, &rect, LVIR_SELECTBOUNDS); |
698 |
+ |
|
699 |
+ |
spot.x = rect.left; |
700 |
+ |
spot.y = rect.top; |
701 |
+ |
} |
702 |
+ |
else |
703 |
+ |
{ |
704 |
+ |
break; |
705 |
+ |
} |
706 |
+ |
|
707 |
+ |
ClientToScreen(GetDlgItem(dialog, IDC_SELECT_SCANS), &spot); |
708 |
+ |
|
709 |
+ |
int code = TrackPopupMenuEx(data->popup, TPM_LEFTALIGN | |
710 |
+ |
TPM_TOPALIGN | TPM_NONOTIFY | TPM_RETURNCMD | TPM_RIGHTBUTTON, |
711 |
+ |
spot.x, spot.y, GetDlgItem(dialog, IDC_SELECT_SCANS), NULL); |
712 |
+ |
|
713 |
+ |
switch (code) |
714 |
+ |
{ |
715 |
+ |
case 1: |
716 |
+ |
ShellExecute(dialog, NULL, scan, NULL, NULL, SW_SHOWDEFAULT); |
717 |
+ |
break; |
718 |
+ |
case 2: |
719 |
+ |
{ |
720 |
+ |
SHELLEXECUTEINFO info; |
721 |
+ |
|
722 |
+ |
info.cbSize = sizeof(info); |
723 |
+ |
info.fMask = SEE_MASK_INVOKEIDLIST; |
724 |
+ |
info.hwnd = dialog; |
725 |
+ |
info.lpVerb = "properties"; |
726 |
+ |
info.lpFile = scan; |
727 |
+ |
info.lpParameters = NULL; |
728 |
+ |
info.lpDirectory = NULL; |
729 |
+ |
info.nShow = SW_SHOWDEFAULT; |
730 |
+ |
info.lpIDList = NULL; |
731 |
+ |
|
732 |
+ |
ShellExecuteEx(&info); |
733 |
+ |
} |
734 |
+ |
break; |
735 |
+ |
} |
736 |
+ |
} |
737 |
+ |
break; |
738 |
+ |
} |
739 |
+ |
|
740 |
+ |
return FALSE; |
741 |
+ |
} |
742 |
+ |
|
743 |
+ |
INT_PTR ScanUtility::enter(HWND dialog, UINT msg, WPARAM w, LPARAM l) |
744 |
+ |
{ |
745 |
+ |
ScanUtility* data = which(dialog); |
746 |
+ |
|
747 |
+ |
switch (msg) |
748 |
+ |
{ |
749 |
+ |
case WM_INITDIALOG: |
750 |
+ |
data = which(dialog, l); |
751 |
+ |
{ |
752 |
+ |
ostringstream enter; |
753 |
+ |
|
754 |
+ |
enter << "Enter the client name and number."; |
755 |
+ |
|
756 |
+ |
SetDlgItemText(dialog, IDC_ENTER_TEXT, enter.str().c_str()); |
757 |
+ |
} |
758 |
+ |
break; |
759 |
+ |
case WM_NOTIFY: |
760 |
+ |
{ |
761 |
+ |
LPNMHDR nm = LPNMHDR(l); |
762 |
+ |
|
763 |
+ |
switch (nm->code) |
764 |
+ |
{ |
765 |
+ |
case PSN_SETACTIVE: |
766 |
+ |
if (data->client.getName() != "" && data->client.getNumber() != |
767 |
+ |
0) |
768 |
+ |
{ |
769 |
+ |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
770 |
+ |
PSWIZB_NEXT); |
771 |
+ |
} |
772 |
+ |
else |
773 |
+ |
{ |
774 |
+ |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK); |
775 |
+ |
} |
776 |
+ |
|
777 |
+ |
SetDlgItemText(dialog, IDC_ENTER_NAME, |
778 |
+ |
data->client.getName().c_str()); |
779 |
+ |
|
780 |
+ |
if (data->client.getNumber() != 0) |
781 |
+ |
{ |
782 |
+ |
SetDlgItemInt(dialog, IDC_ENTER_NUM, |
783 |
+ |
data->client.getNumber(), FALSE); |
784 |
+ |
} |
785 |
+ |
else |
786 |
+ |
{ |
787 |
+ |
SetDlgItemText(dialog, IDC_ENTER_NUM, ""); |
788 |
+ |
} |
789 |
+ |
break; |
790 |
+ |
case PSN_WIZBACK: |
791 |
+ |
break; |
792 |
+ |
case PSN_WIZNEXT: |
793 |
+ |
if (debug) |
794 |
+ |
{ |
795 |
+ |
cerr << "client = {\n" |
796 |
+ |
<< " name = " << data->client.getName() << "\n" |
797 |
+ |
<< " number = " << data->client.getNumber() << "\n" |
798 |
+ |
<< "}\n"; |
799 |
+ |
} |
800 |
|
break; |
801 |
|
} |
802 |
|
} |
803 |
|
break; |
804 |
|
case WM_COMMAND: |
805 |
+ |
switch (LOWORD(w)) |
806 |
+ |
{ |
807 |
+ |
case IDC_ENTER_NAME: |
808 |
+ |
{ |
809 |
+ |
char name[BUFSIZ]; |
810 |
+ |
|
811 |
+ |
GetDlgItemText(dialog, IDC_ENTER_NAME, name, BUFSIZ); |
812 |
+ |
|
813 |
+ |
if (name != data->client.getName()) |
814 |
+ |
{ |
815 |
+ |
data->client.setName(name); |
816 |
+ |
} |
817 |
+ |
} |
818 |
+ |
|
819 |
+ |
if (data->client.getName() != "" && data->client.getNumber() != 0) |
820 |
+ |
{ |
821 |
+ |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
822 |
+ |
PSWIZB_NEXT); |
823 |
+ |
} |
824 |
+ |
else |
825 |
+ |
{ |
826 |
+ |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK); |
827 |
+ |
} |
828 |
+ |
break; |
829 |
+ |
case IDC_ENTER_NUM: |
830 |
+ |
{ |
831 |
+ |
unsigned number = GetDlgItemInt(dialog, IDC_ENTER_NUM, NULL, |
832 |
+ |
FALSE); |
833 |
+ |
|
834 |
+ |
if (number != data->client.getNumber()) |
835 |
+ |
{ |
836 |
+ |
data->client.setNumber(number); |
837 |
+ |
} |
838 |
+ |
} |
839 |
+ |
|
840 |
+ |
if (data->client.getName() != "" && data->client.getNumber() != 0) |
841 |
+ |
{ |
842 |
+ |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
843 |
+ |
PSWIZB_NEXT); |
844 |
+ |
} |
845 |
+ |
else |
846 |
+ |
{ |
847 |
+ |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK); |
848 |
+ |
} |
849 |
+ |
break; |
850 |
+ |
} |
851 |
|
break; |
852 |
|
} |
853 |
|
|