2 |
|
// |
3 |
|
// Douglas Thrift |
4 |
|
// |
5 |
< |
// $Id: Chooser.cxx,v 1.3 2003/08/17 03:55:39 douglas Exp $ |
5 |
> |
// $Id: Chooser.cxx,v 1.5 2003/08/18 22:25:29 douglas Exp $ |
6 |
|
|
7 |
|
#include "Chooser.h" |
8 |
|
|
9 |
< |
INT_PTR CALLBACK smersh(HWND dialog, UINT msg, WPARAM w, LPARAM l); |
9 |
> |
Chooser::Chooser() |
10 |
> |
{ |
11 |
> |
shortcut = false; |
12 |
> |
choice = none; |
13 |
> |
number = count++; |
14 |
> |
choosers.insert(pair<unsigned, Chooser*>(number, this)); |
15 |
> |
} |
16 |
|
|
17 |
< |
struct |
17 |
> |
Chooser::~Chooser() |
18 |
|
{ |
19 |
< |
bool* shortcut; |
14 |
< |
Mode* choice; |
19 |
> |
choosers.erase(number); |
20 |
|
} |
16 |
– |
cheese; |
21 |
|
|
22 |
|
Mode Chooser::choose(HWND parent) |
23 |
|
{ |
24 |
< |
cheese.shortcut = &shortcut; |
25 |
< |
cheese.choice = &choice; |
22 |
< |
|
23 |
< |
DialogBox(gui.instance, MAKEINTRESOURCE(IDD_CHOICE), parent, smersh); |
24 |
> |
DialogBoxParam(gui.instance, MAKEINTRESOURCE(IDD_CHOICE), parent, |
25 |
> |
Chooser::window, number); |
26 |
|
|
27 |
|
desktop(); |
28 |
|
|
29 |
|
return choice; |
30 |
|
} |
31 |
|
|
32 |
+ |
INT_PTR CALLBACK Chooser::window(HWND dialog, UINT msg, WPARAM w, LPARAM l) |
33 |
+ |
{ |
34 |
+ |
map<HWND, Chooser*>::iterator itor = windows.find(dialog); |
35 |
+ |
Chooser* data = itor->second; |
36 |
+ |
Mode* choice = &data->choice; |
37 |
+ |
bool* shortcut = &data->shortcut; |
38 |
+ |
|
39 |
+ |
switch (msg) |
40 |
+ |
{ |
41 |
+ |
case WM_INITDIALOG: |
42 |
+ |
center(dialog); |
43 |
+ |
SendMessage(dialog, WM_SETICON, ICON_BIG, LPARAM(gui.icon)); |
44 |
+ |
SendMessage(dialog, WM_SETTEXT, 0, LPARAM(programName.c_str())); |
45 |
+ |
{ |
46 |
+ |
map<unsigned, Chooser*>::iterator itor = choosers.find(l); |
47 |
+ |
|
48 |
+ |
windows.insert(pair<HWND, Chooser*>(dialog, itor->second)); |
49 |
+ |
} |
50 |
+ |
break; |
51 |
+ |
case WM_COMMAND: |
52 |
+ |
switch (LOWORD(w)) |
53 |
+ |
{ |
54 |
+ |
case IDC_CHOICE_DISC: |
55 |
+ |
*choice = disc; |
56 |
+ |
if (debug) cerr << "choice = disc\n"; |
57 |
+ |
EnableWindow(GetDlgItem(dialog, IDC_CHOICE_ALWAYS), TRUE); |
58 |
+ |
EnableWindow(GetDlgItem(dialog, IDOK), TRUE); |
59 |
+ |
break; |
60 |
+ |
case IDC_CHOICE_SCAN: |
61 |
+ |
*choice = scan; |
62 |
+ |
if (debug) cerr << "choice = scan\n"; |
63 |
+ |
EnableWindow(GetDlgItem(dialog, IDC_CHOICE_ALWAYS), TRUE); |
64 |
+ |
EnableWindow(GetDlgItem(dialog, IDOK), TRUE); |
65 |
+ |
break; |
66 |
+ |
case IDC_CHOICE_ALWAYS: |
67 |
+ |
*shortcut = !*shortcut; |
68 |
+ |
if (debug) cerr << "shortcut = " << *shortcut << "\n"; |
69 |
+ |
break; |
70 |
+ |
case IDCANCEL: |
71 |
+ |
*choice = none; |
72 |
+ |
case IDOK: |
73 |
+ |
windows.erase(dialog); |
74 |
+ |
EndDialog(dialog, w); |
75 |
+ |
return TRUE; |
76 |
+ |
default: |
77 |
+ |
break; |
78 |
+ |
} |
79 |
+ |
break; |
80 |
+ |
} |
81 |
+ |
|
82 |
+ |
return FALSE; |
83 |
+ |
} |
84 |
+ |
|
85 |
+ |
unsigned Chooser::count = 0; |
86 |
+ |
map<unsigned, Chooser*> Chooser::choosers; |
87 |
+ |
map<HWND, Chooser*> Chooser::windows; |
88 |
+ |
|
89 |
|
void Chooser::desktop(void) |
90 |
|
{ |
91 |
|
if (!shortcut || choice == none) return; |
131 |
|
file->Release(); |
132 |
|
link->Release(); |
133 |
|
|
134 |
< |
CoUninitialize(); |
76 |
< |
} |
77 |
< |
|
78 |
< |
INT_PTR CALLBACK smersh(HWND dialog, UINT msg, WPARAM w, LPARAM l) |
79 |
< |
{ |
80 |
< |
switch (msg) |
81 |
< |
{ |
82 |
< |
case WM_INITDIALOG: |
83 |
< |
center(dialog); |
84 |
< |
SendMessage(dialog, WM_SETICON, ICON_BIG, LPARAM(gui.icon)); |
85 |
< |
SendMessage(dialog, WM_SETTEXT, 0, LPARAM(programName.c_str())); |
86 |
< |
break; |
87 |
< |
case WM_COMMAND: |
88 |
< |
switch (LOWORD(w)) |
89 |
< |
{ |
90 |
< |
case IDC_CHOICE_DISC: |
91 |
< |
*cheese.choice = disc; |
92 |
< |
if (debug) cerr << "choice = disc\n"; |
93 |
< |
EnableWindow(GetDlgItem(dialog, IDC_CHOICE_ALWAYS), TRUE); |
94 |
< |
EnableWindow(GetDlgItem(dialog, IDOK), TRUE); |
95 |
< |
break; |
96 |
< |
case IDC_CHOICE_SCAN: |
97 |
< |
*cheese.choice = scan; |
98 |
< |
if (debug) cerr << "choice = scan\n"; |
99 |
< |
EnableWindow(GetDlgItem(dialog, IDC_CHOICE_ALWAYS), TRUE); |
100 |
< |
EnableWindow(GetDlgItem(dialog, IDOK), TRUE); |
101 |
< |
break; |
102 |
< |
case IDC_CHOICE_ALWAYS: |
103 |
< |
*cheese.shortcut = !*cheese.shortcut; |
104 |
< |
if (debug) cerr << "shortcut = " << *cheese.shortcut << "\n"; |
105 |
< |
break; |
106 |
< |
case IDCANCEL: |
107 |
< |
*cheese.choice = none; |
108 |
< |
case IDOK: |
109 |
< |
EndDialog(dialog, w); |
110 |
< |
return TRUE; |
111 |
< |
default: |
112 |
< |
break; |
113 |
< |
} |
114 |
< |
break; |
115 |
< |
} |
134 |
> |
delete [] desktop; |
135 |
|
|
136 |
< |
return FALSE; |
136 |
> |
CoUninitialize(); |
137 |
|
} |