Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

profassoc.cpp

Go to the documentation of this file.
00001 /****************************************************************************** 00002 00003 Source File: Profile Association Page.CPP 00004 00005 Copyright (c) 1997 by Microsoft Corporation 00006 00007 Change History: 00008 00009 05-09-1997 hideyukn - Created 00010 00011 ******************************************************************************/ 00012 00013 #include "ICMUI.H" 00014 00015 #include "Resource.H" 00016 00017 // It looks like the way to make the icon draw is to subclass the Icon control 00018 // in the window. So, here's a Window Procedure for the subclass 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 // CProfileAssociationPage member functions 00033 00034 // Class Constructor 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 // Class destructor 00048 00049 CProfileAssociationPage::~CProfileAssociationPage() { 00050 if (m_pcpTarget) { 00051 delete m_pcpTarget; 00052 } 00053 } 00054 00055 // Dialog box (property sheet) initialization 00056 00057 BOOL CProfileAssociationPage::OnInit() { 00058 00059 m_pcpTarget = new CProfile(m_csProfile); 00060 00061 if (m_pcpTarget) { 00062 00063 // Set profile filename 00064 00065 SetDlgItemText(m_hwnd, ProfileFilename, m_pcpTarget->GetName()); 00066 00067 // Update ICON to show installed/non-installed status. 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 // Clean up add/delete list. 00077 00078 m_cuaAdd.Empty(); 00079 m_cuaDelete.Empty(); 00080 00081 // Build tentitive association list. 00082 00083 ConstructAssociations(); 00084 00085 // And then, fill up device listbox 00086 00087 UpdateDeviceListBox(); 00088 00089 // And set focus on AddButton. 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 // Private ConstructAssociations function- this constructs the list of 00104 // tentative associations- this starts out as the true list from the profile 00105 // object. 00106 00107 VOID CProfileAssociationPage::ConstructAssociations() { 00108 00109 m_cuaAssociate.Empty(); // Clean it up! 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()) // Not yet deleted 00121 m_cuaAssociate.Add(m_pcpTarget->Association(u)); 00122 } 00123 00124 // Now, add any added associations 00125 00126 for (u = 0; u < m_cuaAdd.Count(); u++) 00127 m_cuaAssociate.Add(m_cuaAdd[u]); 00128 } 00129 00130 // Public method for noting tentative associations to be added 00131 00132 void CProfileAssociationPage::Associate(unsigned uAdd) { 00133 00134 // First, see if it's on the delete list. If it is, remove it from there 00135 // Otherwise, add us to the add list, if it's a new association. 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 // Public Method for removing tentative associations 00155 00156 void CProfileAssociationPage::Dissociate(unsigned uRemove) { 00157 00158 // First, see if it's on the add list. If it is, remove it from there 00159 // Otherwise, add us to the delete list. 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 // Add the associations to the list 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 // If there are no associations, disable the Remove Devices button 00187 00188 HWND hwndRemove = GetDlgItem(m_hwnd,RemoveButton); 00189 00190 // If there are no more devices, or all are associated, disable the Add 00191 // Devices button. 00192 // 00193 // !!! To get more performance !!! 00194 // 00195 // EnableWindow(GetDlgItem(m_hwnd, AddButton), 00196 // m_pcpTarget->DeviceCount() && m_pcpTarget->DeviceCount() > AssociationCount()); 00197 // 00198 // !!! AddButton NEVER DISABLED !!! 00199 // 00200 00201 // If focus is on Remove, move it to Add button. 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 // If there is any device, set focus to 1st entry. 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; // still need to handle this message by def. proc. 00274 } 00275 00276 // Common control notification override 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 // Disable apply button, because current request are 00287 // going to be "Applied". 00288 00289 DisableApplyButton(); 00290 00291 // We are going to update changed. 00292 00293 SettingChanged(FALSE); 00294 00295 // Remove any associations we're removing 00296 00297 while (m_cuaDelete.Count()) { 00298 m_pcpTarget->Dissociate(m_pcpTarget->DeviceName(m_cuaDelete[0])); 00299 m_cuaDelete.Remove(0); 00300 } 00301 00302 // Add any associations we're adding 00303 00304 while (m_cuaAdd.Count()) { 00305 m_pcpTarget->Associate(m_pcpTarget->DeviceName(m_cuaAdd[0])); 00306 m_cuaAdd.Remove(0); 00307 } 00308 00309 // Re-create CProfile object. 00310 // 00311 // !!! Need to be done some performance work here. 00312 00313 delete m_pcpTarget; 00314 m_pcpTarget = new CProfile(m_csProfile); 00315 00316 if (!m_pcpTarget) 00317 { 00318 // BUGBUG proper error should happen. 00319 00320 return FALSE; 00321 } 00322 00323 // Re-Build tentitive association list. 00324 00325 ConstructAssociations(); 00326 00327 UpdateDeviceListBox(); 00328 00329 // check the install status to refect icon. 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 // Context-sensitive help handler 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 // Context Help for AddDevice Dialog. 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 // CAddDeviceDialog class constructor 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 // Dialog Initialization routine 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 // This must not list associated (tentatively) devices, per the spec 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; // Don't insert this one... 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 // Dialog notification handler 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 // Selection has been made. 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 // Context-sensitive help handler 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

Generated on Sat May 15 19:41:27 2004 for test by doxygen 1.3.7