2 |
|
// |
3 |
|
// Douglas Thrift |
4 |
|
// |
5 |
< |
// $Id: ScanUtility.cxx,v 1.7 2003/08/22 06:30:14 douglas Exp $ |
5 |
> |
// $Id: ScanUtility.cxx,v 1.8 2003/08/24 07:31:45 douglas Exp $ |
6 |
|
|
7 |
|
#include "ScanUtility.h" |
8 |
|
|
15 |
|
sprintf(title, "%s - Scan Utility", programName.c_str()); |
16 |
|
loadDirs(); |
17 |
|
|
18 |
< |
menu = LoadMenu(gui.instance, MAKEINTRESOURCE(IDR_SELECT)); |
19 |
< |
popup = GetSubMenu(menu, 0); |
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]); |
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 |
|
} |
83 |
|
ScanUtility::~ScanUtility() |
84 |
|
{ |
85 |
|
DestroyMenu(popup); |
63 |
– |
DestroyMenu(menu); |
86 |
|
utilities.erase(number); |
87 |
|
saveDirs(); |
88 |
|
|
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); |
473 |
< |
ScanUtility* data = itor->second; |
511 |
> |
ScanUtility* data = which(dialog); |
512 |
|
|
513 |
|
switch (msg) |
514 |
|
{ |
515 |
|
case WM_INITDIALOG: |
516 |
|
center(GetParent(dialog)); |
517 |
|
SendMessage(GetParent(dialog), WM_SETICON, ICON_BIG, LPARAM(gui.icon)); |
518 |
< |
{ |
519 |
< |
LPPROPSHEETPAGE page = LPPROPSHEETPAGE(l); |
482 |
< |
map<unsigned, ScanUtility*>::iterator itor = |
483 |
< |
utilities.find(page->lParam); |
518 |
> |
|
519 |
> |
data = which(dialog, l); |
520 |
|
|
485 |
– |
windows.insert(pair<HWND, ScanUtility*>(dialog, itor->second)); |
486 |
– |
} |
521 |
|
{ |
522 |
|
ostringstream instructions; |
523 |
|
|
583 |
|
|
584 |
|
INT_PTR ScanUtility::select(HWND dialog, UINT msg, WPARAM w, LPARAM l) |
585 |
|
{ |
586 |
< |
map<HWND, ScanUtility*>::iterator itor = windows.find(dialog); |
553 |
< |
ScanUtility* data = itor->second; |
586 |
> |
ScanUtility* data = which(dialog); |
587 |
|
|
588 |
|
switch (msg) |
589 |
|
{ |
590 |
|
case WM_INITDIALOG: |
591 |
< |
{ |
559 |
< |
LPPROPSHEETPAGE page = LPPROPSHEETPAGE(l); |
560 |
< |
map<unsigned, ScanUtility*>::iterator itor = |
561 |
< |
utilities.find(page->lParam); |
591 |
> |
data = which(dialog, l); |
592 |
|
|
563 |
– |
windows.insert(pair<HWND, ScanUtility*>(dialog, itor->second)); |
564 |
– |
} |
593 |
|
{ |
594 |
|
ostringstream select; |
595 |
|
|
597 |
|
|
598 |
|
SetDlgItemText(dialog, IDC_SELECT_TEXT, select.str().c_str()); |
599 |
|
} |
600 |
+ |
|
601 |
|
{ |
602 |
|
LVCOLUMN column; |
603 |
|
|
617 |
|
|
618 |
|
switch (ni->hdr.code) |
619 |
|
{ |
591 |
– |
case NM_RCLICK: |
592 |
– |
{ |
593 |
– |
char scan[MAX_PATH]; |
594 |
– |
|
595 |
– |
ListView_GetItemText(GetDlgItem(dialog, IDC_SELECT_SCANS), |
596 |
– |
ni->iItem, 0, scan, MAX_PATH); |
597 |
– |
|
598 |
– |
SHELLEXECUTEINFO info; |
599 |
– |
|
600 |
– |
info.cbSize = sizeof(info); |
601 |
– |
info.fMask = SEE_MASK_INVOKEIDLIST; |
602 |
– |
info.hwnd = dialog; |
603 |
– |
info.lpVerb = "properties"; |
604 |
– |
info.lpFile = scan; |
605 |
– |
info.lpParameters = NULL; |
606 |
– |
info.lpDirectory = NULL; |
607 |
– |
info.nShow = SW_SHOWDEFAULT; |
608 |
– |
info.lpIDList = NULL; |
609 |
– |
|
610 |
– |
ShellExecuteEx(&info); |
611 |
– |
} |
612 |
– |
break; |
620 |
|
case NM_DBLCLK: |
621 |
|
{ |
622 |
|
char scan[MAX_PATH]; |
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 |
|
{ |
655 |
|
|
656 |
|
data->scan = scan; |
657 |
|
} |
658 |
+ |
|
659 |
|
ListView_DeleteAllItems(GetDlgItem(dialog, IDC_SELECT_SCANS)); |
660 |
+ |
|
661 |
|
if (debug) cerr << "scan = " << data->scan << "\n"; |
652 |
– |
ShellExecute(dialog, NULL, data->scan.c_str(), NULL, NULL, |
653 |
– |
SW_SHOWDEFAULT); |
662 |
|
break; |
663 |
|
} |
664 |
|
} |
665 |
|
break; |
666 |
< |
case WM_COMMAND: |
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 |
|
|
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 |
+ |
|
854 |
|
return FALSE; |
855 |
|
} |