00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
#include "ICMUI.H"
00014
00015
#include "Resource.H"
00016
00017
00018
00019
00020 CONST
DWORD ProfileAssociationUIHelpIds[] = {
00021
AddButton,
IDH_ASSOCDEVICE_ADD,
00022
RemoveButton,
IDH_ASSOCDEVICE_REMOVE,
00023
#if !defined(_WIN95_) // context-sentitive help
00024
ProfileFilename,
IDH_ASSOCDEVICE_NAME,
00025
DeviceListControl,
IDH_ASSOCDEVICE_LIST,
00026
DeviceListControlText,
IDH_ASSOCDEVICE_LIST,
00027
StatusIcon,
IDH_DISABLED,
00028
#endif
00029
0, 0
00030 };
00031
00032
00033
00034
00035
00036 CProfileAssociationPage::CProfileAssociationPage(HINSTANCE hiWhere,
00037 LPCTSTR lpstrTarget) {
00038
m_pcpTarget =
NULL;
00039
m_csProfile = lpstrTarget;
00040 m_psp.dwSize =
sizeof m_psp;
00041 m_psp.dwFlags |= PSP_USETITLE;
00042 m_psp.hInstance = hiWhere;
00043 m_psp.pszTemplate = MAKEINTRESOURCE(
AssociateDevicePage);
00044 m_psp.pszTitle = MAKEINTRESOURCE(
AssociatePropertyString);
00045 }
00046
00047
00048
00049 CProfileAssociationPage::~CProfileAssociationPage() {
00050
if (
m_pcpTarget) {
00051
delete m_pcpTarget;
00052 }
00053 }
00054
00055
00056
00057 BOOL CProfileAssociationPage::OnInit() {
00058
00059
m_pcpTarget =
new CProfile(
m_csProfile);
00060
00061
if (
m_pcpTarget) {
00062
00063
00064
00065
SetDlgItemText(m_hwnd,
ProfileFilename,
m_pcpTarget->
GetName());
00066
00067
00068
00069 HICON hIcon = LoadIcon(CGlobals::Instance(),
00070 MAKEINTRESOURCE(
m_pcpTarget->
IsInstalled() ?
DefaultIcon :
UninstalledIcon));
00071
00072
if (hIcon) {
00073
SendDlgItemMessage(m_hwnd,
StatusIcon, STM_SETICON, (WPARAM) hIcon, 0);
00074 }
00075
00076
00077
00078
m_cuaAdd.
Empty();
00079
m_cuaDelete.
Empty();
00080
00081
00082
00083
ConstructAssociations();
00084
00085
00086
00087
UpdateDeviceListBox();
00088
00089
00090
00091
SetFocus(
GetDlgItem(m_hwnd,
AddButton));
00092
00093
DisableApplyButton();
00094
SettingChanged(
FALSE);
00095
00096
return TRUE;
00097
00098 }
else {
00099
return FALSE;
00100 }
00101 }
00102
00103
00104
00105
00106
00107 VOID CProfileAssociationPage::ConstructAssociations() {
00108
00109
m_cuaAssociate.
Empty();
00110
00111
for (
unsigned u = 0; u <
m_pcpTarget->
AssociationCount(); u++) {
00112
00113
for (
unsigned uDelete = 0;
00114 uDelete <
m_cuaDelete.
Count();
00115 uDelete++) {
00116
if (
m_cuaDelete[uDelete] ==
m_pcpTarget->
Association(u))
00117
break;
00118 }
00119
00120
if (uDelete ==
m_cuaDelete.
Count())
00121
m_cuaAssociate.
Add(
m_pcpTarget->
Association(u));
00122 }
00123
00124
00125
00126
for (u = 0; u <
m_cuaAdd.
Count(); u++)
00127
m_cuaAssociate.
Add(
m_cuaAdd[u]);
00128 }
00129
00130
00131
00132 void CProfileAssociationPage::Associate(
unsigned uAdd) {
00133
00134
00135
00136
00137
for (
unsigned u = 0; u <
m_cuaDelete.
Count(); u++)
00138
if (uAdd ==
m_cuaDelete[u])
00139
break;
00140
00141
if (u < m_cuaDelete.Count())
00142 m_cuaDelete.Remove(u);
00143
else {
00144
for (u = 0; u <
m_cuaAssociate.
Count(); u++)
00145
if (
m_cuaAssociate[u] == uAdd)
00146
break;
00147
if (u ==
m_cuaAssociate.
Count())
00148
m_cuaAdd.
Add(uAdd);
00149 }
00150
00151
DeviceListChanged();
00152 }
00153
00154
00155
00156 void CProfileAssociationPage::Dissociate(
unsigned uRemove) {
00157
00158
00159
00160
00161
for (
unsigned u = 0; u <
m_cuaAdd.
Count(); u++)
00162
if (uRemove ==
m_cuaAdd[u])
00163
break;
00164
00165
if (u < m_cuaAdd.Count())
00166 m_cuaAdd.Remove(u);
00167
else
00168
m_cuaDelete.
Add(uRemove);
00169
00170
DeviceListChanged();
00171 }
00172
00173 VOID CProfileAssociationPage::UpdateDeviceListBox() {
00174
00175
00176
00177
SendDlgItemMessage(m_hwnd,
DeviceListControl, LB_RESETCONTENT, 0, 0);
00178
00179
for (
unsigned u = 0; u <
AssociationCount(); u++ ) {
00180 LRESULT iItem =
SendDlgItemMessage(m_hwnd,
DeviceListControl, LB_ADDSTRING,
00181 0, (LPARAM)
DisplayName(u));
00182
SendDlgItemMessage(m_hwnd,
DeviceListControl, LB_SETITEMDATA, iItem,
00183 (LPARAM)
Association(u));
00184 }
00185
00186
00187
00188 HWND hwndRemove =
GetDlgItem(m_hwnd,
RemoveButton);
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
if (
GetFocus() == hwndRemove) {
00204
00205 HWND hwndAdd =
GetDlgItem(m_hwnd,
AddButton);
00206
00207
SetFocus(hwndAdd);
00208
SendMessage(hwndRemove, BM_SETSTYLE, BS_PUSHBUTTON, MAKELPARAM(
TRUE, 0));
00209
SendMessage(hwndAdd, BM_SETSTYLE, BS_DEFPUSHBUTTON, MAKELPARAM(
TRUE, 0));
00210 }
00211
00212
EnableWindow(hwndRemove, !!(
AssociationCount()));
00213
00214
00215
00216
if (
SendDlgItemMessage(m_hwnd,
DeviceListControl, LB_GETCOUNT, 0, 0))
00217
SendDlgItemMessage(m_hwnd,
DeviceListControl, LB_SETCURSEL, 0, 0);
00218 }
00219
00220 BOOL CProfileAssociationPage::OnCommand(WORD wNotifyCode, WORD wid, HWND hwndControl) {
00221
00222
switch (wid) {
00223
00224
case AddButton :
00225
if (wNotifyCode == BN_CLICKED) {
00226
CAddDeviceDialog cadd(
this, m_hwnd);
00227
if (!cadd.
bCanceled()) {
00228
UpdateDeviceListBox();
00229
EnableApplyButton();
00230
SettingChanged(
TRUE);
00231 }
00232
return TRUE;
00233 }
00234
break;
00235
00236
case RemoveButton :
00237
if (wNotifyCode == BN_CLICKED) {
00238 LRESULT i =
SendDlgItemMessage(m_hwnd,
DeviceListControl,
00239 LB_GETCURSEL, 0, 0);
00240
00241
if (i == -1)
00242
return TRUE;
00243
00244
unsigned uItem = (
unsigned)
SendDlgItemMessage(m_hwnd,
DeviceListControl,
00245 LB_GETITEMDATA, i, 0);
00246
Dissociate(uItem);
00247
UpdateDeviceListBox();
00248
EnableApplyButton();
00249
SettingChanged(
TRUE);
00250
return TRUE;
00251 }
00252
break;
00253
00254
case DeviceListControl :
00255
if (wNotifyCode == LBN_SELCHANGE) {
00256
EnableWindow(
GetDlgItem(m_hwnd,
RemoveButton),
00257 -1 !=
SendDlgItemMessage(m_hwnd,
DeviceListControl, LB_GETCURSEL, 0, 0));
00258
return TRUE;
00259 }
00260
break;
00261 }
00262
00263
return TRUE;
00264 }
00265
00266 BOOL CProfileAssociationPage::OnDestroy() {
00267
00268
if (
m_pcpTarget) {
00269
delete m_pcpTarget;
00270
m_pcpTarget = (
CProfile *)
NULL;
00271 }
00272
00273
return FALSE;
00274 }
00275
00276
00277
00278 BOOL CProfileAssociationPage::OnNotify(
int idCtrl, LPNMHDR pnmh) {
00279
00280
switch (pnmh -> code) {
00281
00282
case PSN_APPLY: {
00283
00284
if (
SettingChanged()) {
00285
00286
00287
00288
00289
DisableApplyButton();
00290
00291
00292
00293
SettingChanged(
FALSE);
00294
00295
00296
00297
while (
m_cuaDelete.
Count()) {
00298
m_pcpTarget->
Dissociate(
m_pcpTarget->
DeviceName(
m_cuaDelete[0]));
00299
m_cuaDelete.
Remove(0);
00300 }
00301
00302
00303
00304
while (
m_cuaAdd.
Count()) {
00305
m_pcpTarget->
Associate(
m_pcpTarget->
DeviceName(
m_cuaAdd[0]));
00306
m_cuaAdd.
Remove(0);
00307 }
00308
00309
00310
00311
00312
00313
delete m_pcpTarget;
00314
m_pcpTarget =
new CProfile(
m_csProfile);
00315
00316
if (!
m_pcpTarget)
00317 {
00318
00319
00320
return FALSE;
00321 }
00322
00323
00324
00325
ConstructAssociations();
00326
00327
UpdateDeviceListBox();
00328
00329
00330
00331 HICON hIcon = LoadIcon(CGlobals::Instance(),
00332 MAKEINTRESOURCE(
m_pcpTarget->
IsInstalled() ?
DefaultIcon :
UninstalledIcon));
00333
00334
if (hIcon) {
00335
SendDlgItemMessage(m_hwnd,
StatusIcon, STM_SETICON, (WPARAM) hIcon, 0);
00336 }
00337 }
00338
00339
break;
00340 }
00341 }
00342
00343
return TRUE;
00344 }
00345
00346
00347
00348 BOOL CProfileAssociationPage::OnHelp(LPHELPINFO pHelp) {
00349
00350
if (pHelp->iContextType == HELPINFO_WINDOW) {
00351 WinHelp((HWND) pHelp->hItemHandle,
WINDOWS_HELP_FILE,
00352 HELP_WM_HELP, (ULONG_PTR) (LPSTR)
ProfileAssociationUIHelpIds);
00353 }
00354
00355
return (
TRUE);
00356 }
00357
00358 BOOL CProfileAssociationPage::OnContextMenu(HWND hwnd) {
00359
00360
DWORD iCtrlID =
GetDlgCtrlID(hwnd);
00361
00362 WinHelp(hwnd,
WINDOWS_HELP_FILE,
00363 HELP_CONTEXTMENU, (ULONG_PTR) (LPSTR)
ProfileAssociationUIHelpIds);
00364
00365
return (
TRUE);
00366 }
00367
00368
00369
00370 CONST
DWORD AddDeviceUIHelpIds[] = {
00371
AddDeviceButton,
IDH_ADDDEVICEUI_ADD,
00372
DeviceListControl,
IDH_ADDDEVICEUI_LIST,
00373
DeviceListControlText,
IDH_ADDDEVICEUI_LIST,
00374 0, 0
00375 };
00376
00377
00378
00379 CAddDeviceDialog::CAddDeviceDialog(
CProfileAssociationPage *pcpas,
00380 HWND hwndParent) :
00381
CDialog(pcpas->Instance(),
AddDeviceDialog, hwndParent) {
00382
m_pcpasBoss = pcpas;
00383
m_bCanceled =
TRUE;
00384
DoModal();
00385 }
00386
00387
00388
00389 BOOL CAddDeviceDialog::OnInit() {
00390
00391
CProfile * pcpThis =
m_pcpasBoss->
Profile();
00392
00393
m_hwndList =
GetDlgItem(m_hwnd,
DeviceListControl);
00394
m_hwndButton =
GetDlgItem(m_hwnd,
AddDeviceButton);
00395
00396
00397
00398
for (
unsigned uDevice = 0; uDevice < pcpThis->
DeviceCount(); uDevice++) {
00399
for (
unsigned u = 0; u <
m_pcpasBoss->
AssociationCount(); u++)
00400
if (uDevice ==
m_pcpasBoss->
Association(u))
00401
break;
00402
if (u <
m_pcpasBoss->
AssociationCount())
00403
continue;
00404
00405 LRESULT idItem =
SendMessage(
m_hwndList, LB_ADDSTRING, (WPARAM)0,
00406 (LPARAM) pcpThis->
DisplayName(uDevice));
00407
SendMessage(
m_hwndList, LB_SETITEMDATA, idItem, (LPARAM) uDevice);
00408 }
00409
00410
if (
SendMessage(
m_hwndList, LB_GETCOUNT, 0, 0))
00411
SendMessage(
m_hwndList, LB_SETCURSEL, 0, 0);
00412
00413
EnableWindow(
m_hwndButton, -1 !=
00414
SendMessage(
m_hwndList, LB_GETCURSEL, 0, 0));
00415
00416
return TRUE;
00417 }
00418
00419
00420
00421 BOOL CAddDeviceDialog::OnCommand(WORD wNotification, WORD wid,
00422 HWND hwndControl){
00423
00424
switch (wNotification) {
00425
00426
case LBN_SELCHANGE:
00427
EnableWindow(
m_hwndButton, -1 !=
00428
SendMessage(
m_hwndList, LB_GETCURSEL, 0, 0));
00429
return TRUE;
00430
00431
case BN_CLICKED:
00432
if (wid ==
AddDeviceButton) {
00433
00434 LRESULT i =
SendMessage(
m_hwndList, LB_GETCURSEL, 0, 0);
00435
00436
if (i == -1)
00437
return TRUE;
00438
00439
unsigned uItem = (
unsigned)
SendMessage(
m_hwndList,
00440 LB_GETITEMDATA, i, 0);
00441
00442
m_pcpasBoss->
Associate(uItem);
00443
00444
00445
00446
m_bCanceled =
FALSE;
00447 }
00448
break;
00449
00450
case LBN_DBLCLK:
00451
return OnCommand(BN_CLICKED,
AddDeviceButton,
m_hwndButton);
00452 }
00453
00454
return CDialog::OnCommand(wNotification, wid, hwndControl);
00455 }
00456
00457
00458
00459 BOOL CAddDeviceDialog::OnHelp(LPHELPINFO pHelp) {
00460
00461
if (pHelp->iContextType == HELPINFO_WINDOW) {
00462 WinHelp((HWND) pHelp->hItemHandle,
WINDOWS_HELP_FILE,
00463 HELP_WM_HELP, (ULONG_PTR) (LPSTR)
AddDeviceUIHelpIds);
00464 }
00465
00466
return (
TRUE);
00467 }
00468
00469 BOOL CAddDeviceDialog::OnContextMenu(HWND hwnd) {
00470
00471
DWORD iCtrlID =
GetDlgCtrlID(hwnd);
00472
00473 WinHelp(hwnd,
WINDOWS_HELP_FILE,
00474 HELP_CONTEXTMENU, (ULONG_PTR) (LPSTR)
AddDeviceUIHelpIds);
00475
00476
return (
TRUE);
00477 }
00478
00479