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

CDeviceProfileManagement Class Reference

#include <devprop.h>

Inheritance diagram for CDeviceProfileManagement:

CShellExtensionPage CPropertyPage CMonitorProfileManagement CPrinterProfileManagement CScannerProfileManagement List of all members.

Public Member Functions

 CDeviceProfileManagement (LPCTSTR lpstrName, HINSTANCE hiWhere, int idPage, DWORD dwType)
 ~CDeviceProfileManagement ()
virtual BOOL OnInit ()
virtual BOOL OnCommand (WORD wNotifyCode, WORD wid, HWND hwndCtl)
virtual BOOL OnNotify (int idCtrl, LPNMHDR pnmh)

Protected Member Functions

virtual void InitList ()
virtual void FillList (DWORD dwFlags=0)
void GetDeviceTypeString (DWORD dwType, CString &csDeviceName)

Protected Attributes

CUintArray m_cuaRemovals
CProfileArray m_cpaAdds
CProfileArray m_cpaProfile
CString m_csDevice
HWND m_hwndList
BOOL m_bCMYK
BOOL m_bReadOnly

Private Attributes

DWORD m_dwType

Constructor & Destructor Documentation

CDeviceProfileManagement::CDeviceProfileManagement LPCTSTR  lpstrName,
HINSTANCE  hiWhere,
int  idPage,
DWORD  dwType
 

Definition at line 288 of file devprop.cpp.

References CDeviceProfileManagement(), FALSE, m_bCMYK, m_bReadOnly, m_csDevice, m_dwType, and TRUE.

Referenced by CDeviceProfileManagement().

00290 { 00291 m_csDevice = lpstrDevice; 00292 m_dwType = dwType; 00293 m_psp.hInstance = hiWhere; 00294 m_psp.pszTemplate = MAKEINTRESOURCE(idPage); 00295 00296 // Setting m_bReadOnly to false enables functionality 00297 00298 m_bReadOnly = FALSE; // default setting is false 00299 00300 #if defined(_WIN95_) 00301 00302 // 00303 // There is no way to detect printer supports CMYK or not on Win 9x. 00304 00305 m_bCMYK = TRUE; 00306 00307 #else 00308 00309 // we need to check the device capabilities 00310 // and determine if we're trying to associate 00311 // a cmyk printer profile to a printer that 00312 // doesn't support it. 00313 00314 m_bCMYK = FALSE; // default setting - don't support cmyk 00315 00316 // if the device is a printer 00317 00318 if (m_dwType == CLASS_PRINTER) { 00319 00320 HDC hdcThis = CGlobals::GetPrinterHDC(m_csDevice); 00321 00322 // if the printer supports CMYK 00323 00324 if (hdcThis) { 00325 if (GetDeviceCaps(hdcThis, COLORMGMTCAPS) & CM_CMYK_COLOR) { 00326 m_bCMYK = TRUE; 00327 } 00328 DeleteDC(hdcThis); 00329 } 00330 } 00331 00332 #endif // defined(_WIN95_) 00333 }

CDeviceProfileManagement::~CDeviceProfileManagement  )  [inline]
 

Definition at line 92 of file devprop.h.

00092 {}


Member Function Documentation

void CDeviceProfileManagement::FillList DWORD  dwFlags = 0  )  [protected, virtual]
 

Reimplemented in CPrinterProfileManagement, and CMonitorProfileManagement.

Definition at line 121 of file devprop.cpp.

References AddButton, CUintArray::Count(), CProfileArray::Count(), DEVLIST_CHANGED, DEVLIST_NOSELECT, dwFlags, DWORD, CString::Empty(), CPropertyPage::EnableApplyButton(), EnableWindow(), FALSE, FillList(), GetDlgItem(), GetFocus(), CString::IsEmpty(), m_bReadOnly, m_cpaAdds, m_cpaProfile, m_cuaRemovals, m_hwndList, NULL, RemoveButton, SendMessage(), SetFocus, CPropertyPage::SettingChanged(), and TRUE.

Referenced by FillList(), OnCommand(), OnInit(), and OnNotify().

00121 { 00122 00123 // Before reset list box, get current selection to restore later. 00124 00125 CString csSelect; 00126 00127 csSelect.Empty(); 00128 00129 LRESULT idSelect = LB_ERR; 00130 00131 if ( !(dwFlags & DEVLIST_NOSELECT)) { 00132 00133 // Get current selected position. 00134 00135 idSelect = SendMessage(m_hwndList, LB_GETCURSEL, 0, 0); 00136 00137 // Get text length where currently selected, than allocate buffer for that. 00138 00139 DWORD dwLen = (DWORD) SendMessage(m_hwndList, LB_GETTEXTLEN, idSelect, 0); 00140 TCHAR *pszSelect = new TCHAR[dwLen + 1]; 00141 00142 // Get text itself. 00143 00144 if (pszSelect != NULL) { 00145 00146 if (SendMessage(m_hwndList, LB_GETTEXT, idSelect, (LPARAM) pszSelect) != LB_ERR) { 00147 csSelect = pszSelect; 00148 } 00149 00150 delete pszSelect; 00151 } 00152 } 00153 00154 // reset list box 00155 00156 SendMessage(m_hwndList, LB_RESETCONTENT, 0, 0); 00157 00158 // Fill the profile list box from the list of profiles 00159 00160 for (unsigned u = 0; u < m_cpaProfile.Count(); u++) { 00161 00162 // Don't list profiles tentatively disassociated... 00163 00164 for (unsigned uOut = 0; uOut < m_cuaRemovals.Count(); uOut++) 00165 if (m_cuaRemovals[uOut] == u) 00166 break; 00167 00168 if (uOut < m_cuaRemovals.Count()) 00169 continue; // Don't add this to list, it's been zapped! 00170 00171 LRESULT id = SendMessage(m_hwndList, LB_ADDSTRING, 0, 00172 (LPARAM) (LPCTSTR) m_cpaProfile[u] -> GetName()); 00173 00174 SendMessage(m_hwndList, LB_SETITEMDATA, id, u); 00175 } 00176 00177 // Add the profiles that have been tentatively added... 00178 00179 for (u = 0; u < m_cpaAdds.Count(); u ++) { 00180 LRESULT id = SendMessage(m_hwndList, LB_ADDSTRING, 0, 00181 (LPARAM) (LPCTSTR) m_cpaAdds[u] -> GetName()); 00182 SendMessage(m_hwndList, LB_SETITEMDATA, id, u + m_cpaProfile.Count()); 00183 } 00184 00185 // If we have any profiles, select the first one 00186 // Otherwise, disable the "Remove" button, as there's nothing to remove 00187 00188 unsigned itemCount = (m_cpaProfile.Count() + m_cpaAdds.Count() - m_cuaRemovals.Count()); 00189 00190 if (itemCount) { 00191 00192 // The Remove button must remain disabled 00193 // unless the user is Administrator. 00194 // This code is specific to the Monitor Profile 00195 // Property sheet. 00196 00197 if (!m_bReadOnly) { 00198 EnableWindow(GetDlgItem(m_hwnd, RemoveButton), TRUE); 00199 } 00200 00201 if ( !(dwFlags & DEVLIST_NOSELECT)) { 00202 00203 // Find out the string selected previously. 00204 00205 idSelect = LB_ERR; 00206 00207 if (!csSelect.IsEmpty()) { 00208 idSelect = SendMessage(m_hwndList, LB_FINDSTRINGEXACT, 00209 (WPARAM) -1, (LPARAM) (LPCTSTR) csSelect); 00210 } 00211 00212 // if could not find, just select first item. 00213 00214 if (idSelect == LB_ERR) { 00215 idSelect = 0; 00216 } 00217 00218 // Select it. 00219 00220 SendMessage(m_hwndList, LB_SETCURSEL, idSelect, 0); 00221 } 00222 00223 } else { 00224 00225 HWND hwndRemove = GetDlgItem(m_hwnd, RemoveButton); 00226 00227 // If focus is on Remove, move it to Add button. 00228 00229 if (GetFocus() == hwndRemove) { 00230 00231 HWND hwndAdd = GetDlgItem(m_hwnd, AddButton); 00232 00233 SetFocus(hwndAdd); 00234 SendMessage(hwndRemove, BM_SETSTYLE, BS_PUSHBUTTON, MAKELPARAM(TRUE, 0)); 00235 SendMessage(hwndAdd, BM_SETSTYLE, BS_DEFPUSHBUTTON, MAKELPARAM(TRUE, 0)); 00236 } 00237 00238 EnableWindow(hwndRemove, FALSE); 00239 } 00240 00241 // Apply button needs to remain disabled unless the 00242 // user has permision to make changes - ie. user 00243 // is Administrator. 00244 00245 if ((dwFlags & DEVLIST_CHANGED) && !(m_bReadOnly)) { 00246 EnableApplyButton(); 00247 SettingChanged(TRUE); 00248 } 00249 }

void CDeviceProfileManagement::GetDeviceTypeString DWORD  dwType,
CString csDeviceName
[protected]
 

Definition at line 251 of file devprop.cpp.

References ClassAbstractString, ClassColorSpaceString, ClassLinkString, ClassMonitorString, ClassNamedString, ClassPrinterString, ClassScannerString, DWORD, GetDeviceTypeString(), and CString::Load().

Referenced by GetDeviceTypeString(), and OnCommand().

00251 { 00252 00253 DWORD id; 00254 00255 switch (dwType) { 00256 00257 case CLASS_MONITOR : 00258 id = ClassMonitorString; 00259 break; 00260 case CLASS_PRINTER : 00261 id = ClassPrinterString; 00262 break; 00263 case CLASS_SCANNER : 00264 id = ClassScannerString; 00265 break; 00266 case CLASS_LINK : 00267 id = ClassLinkString; 00268 break; 00269 case CLASS_ABSTRACT : 00270 id = ClassAbstractString; 00271 break; 00272 case CLASS_NAMED : 00273 id = ClassNamedString; 00274 break; 00275 case CLASS_COLORSPACE : 00276 default : 00277 id = ClassColorSpaceString; 00278 break; 00279 } 00280 00281 // Load string. 00282 00283 csDeviceName.Load(id); 00284 }

void CDeviceProfileManagement::InitList  )  [protected, virtual]
 

Reimplemented in CPrinterProfileManagement, and CMonitorProfileManagement.

Definition at line 105 of file devprop.cpp.

References CProfileArray::Empty(), CUintArray::Empty(), m_cpaAdds, m_cpaProfile, m_csDevice, and m_cuaRemovals.

Referenced by CMonitorProfileManagement::InitList(), CPrinterProfileManagement::InitList(), OnInit(), and OnNotify().

00105 { 00106 00107 // Make sure the lists are empty. 00108 00109 m_cuaRemovals.Empty(); 00110 m_cpaAdds.Empty(); 00111 00112 // Determine the associations for the target device. 00113 00114 ENUMTYPE et = {sizeof et, ENUM_TYPE_VERSION, ET_DEVICENAME, m_csDevice}; 00115 00116 CProfile::Enumerate(et, m_cpaProfile); 00117 }

BOOL CDeviceProfileManagement::OnCommand WORD  wNotifyCode,
WORD  wid,
HWND  hwndCtl
[virtual]
 

Reimplemented from CPropertyPage.

Reimplemented in CPrinterProfileManagement, and CMonitorProfileManagement.

Definition at line 360 of file devprop.cpp.

References CUintArray::Add(), CProfileArray::Add(), AddButton, BOOL, CUintArray::Count(), CProfileArray::Count(), DEVLIST_CHANGED, EnableWindow(), FALSE, FillList(), CProfile::GetColorSpace(), GetDeviceTypeString(), GetDlgItem(), CProfile::GetName(), CProfile::GetType(), InstFailedWithName, CProfile::IsValid(), m_bCMYK, m_bReadOnly, m_cpaAdds, m_cpaProfile, m_csDevice, m_cuaRemovals, m_dwType, m_hwndList, MismatchDeviceType, OnCommand(), CAddProfileDialog::ProfileCount(), CAddProfileDialog::ProfileName(), CAddProfileDialog::ProfileNameAndExtension(), CProfileArray::Remove(), CUintArray::Remove(), RemoveButton, SendMessage(), TRUE, and UnsupportedProfile.

Referenced by OnCommand().

00361 { 00362 00363 switch (wNotifyCode) { 00364 00365 case BN_CLICKED: 00366 00367 switch (wid) { 00368 00369 case AddButton: { 00370 00371 unsigned i = 0, u = 0; 00372 00373 // Time to do the old OpenFile dialog stuff... 00374 00375 CAddProfileDialog capd(m_hwnd, m_psp.hInstance); 00376 00377 // See if a profile was selected 00378 00379 while(i < capd.ProfileCount()) { 00380 00381 // Check profile validity and device type 00382 00383 CProfile cpTemp(capd.ProfileName(i)); 00384 00385 // CLASS_COLORSPACE and CLASS_MONITOR can be associated to 00386 // any device. Other (CLASS_SCANNER, CLASS_PRINTER) only 00387 // can be associated to much device. 00388 00389 if ( !cpTemp.IsValid() // Wrong profile type or invalid? 00390 || ( cpTemp.GetType() != m_dwType 00391 && cpTemp.GetType() != CLASS_COLORSPACE 00392 #if 1 // ALLOW_MONITOR_PROFILE_TO_ANY_DEVICE 00393 && cpTemp.GetType() != CLASS_MONITOR 00394 #endif 00395 ) 00396 ) { 00397 00398 // Throw up a message box to inform the user of this 00399 00400 if (cpTemp.IsValid()) 00401 { 00402 CString csDeviceType; GetDeviceTypeString(m_dwType,csDeviceType); 00403 CString csProfileType; GetDeviceTypeString(cpTemp.GetType(),csProfileType); 00404 00405 CGlobals::ReportEx(MismatchDeviceType, m_hwnd, FALSE, 00406 MB_OK|MB_ICONEXCLAMATION, 3, 00407 (LPTSTR)capd.ProfileNameAndExtension(i), 00408 (LPTSTR)csProfileType, 00409 (LPTSTR)csDeviceType); 00410 } 00411 else 00412 { 00413 CGlobals::ReportEx(InstFailedWithName, m_hwnd, FALSE, 00414 MB_OK|MB_ICONEXCLAMATION, 1, 00415 (LPTSTR)capd.ProfileNameAndExtension(i)); 00416 } 00417 00418 goto SkipToNext; 00419 } 00420 00421 // See if the profile has already been listed for addition 00422 00423 for (u = 0; u < m_cpaAdds.Count(); u++) { 00424 if (!lstrcmpi(m_cpaAdds[u] -> GetName(), cpTemp.GetName())) { 00425 goto SkipToNext; // This profile is already added 00426 } 00427 } 00428 00429 // If this profile is on the existing list, either ignore 00430 // or zap it from the removal list, as the case may be 00431 00432 for (u = 0; u < m_cpaProfile.Count(); u++) { 00433 if (!lstrcmpi(m_cpaProfile[u] -> GetName(), 00434 cpTemp.GetName())) { 00435 // Is this one on the removal list? 00436 for (unsigned uOut = 0; 00437 uOut < m_cuaRemovals.Count(); 00438 uOut++) { 00439 if (m_cuaRemovals[uOut] == u) { 00440 // Was to be removed- undo that... 00441 m_cuaRemovals.Remove(uOut); 00442 FillList(DEVLIST_CHANGED); 00443 break; 00444 } 00445 } 00446 goto SkipToNext; 00447 } // End of name in existing list 00448 } 00449 00450 // We need to check the device capabilities 00451 // and determine if we're trying to associate 00452 // a cmyk printer profile to a printer that 00453 // doesn't support it. 00454 00455 if ((!m_bCMYK) && (cpTemp.GetColorSpace() == SPACE_CMYK)) { 00456 CGlobals::ReportEx(UnsupportedProfile, m_hwnd, FALSE, 00457 MB_OK|MB_ICONEXCLAMATION, 2, 00458 (LPTSTR)m_csDevice, 00459 (LPTSTR)capd.ProfileNameAndExtension(i)); 00460 goto SkipToNext; 00461 } 00462 00463 // Add this profile to the list, item (max orig + index) 00464 00465 m_cpaAdds.Add(capd.ProfileName(i)); 00466 00467 // Change has been made, update the list 00468 00469 FillList(DEVLIST_CHANGED); 00470 SkipToNext: 00471 i++; 00472 } 00473 00474 return TRUE; 00475 } 00476 00477 case RemoveButton: { 00478 00479 // Remove the selected profile 00480 00481 LRESULT id = SendMessage(m_hwndList, LB_GETCURSEL, 0, 0); 00482 unsigned u = (unsigned) SendMessage(m_hwndList, 00483 LB_GETITEMDATA, id, 0); 00484 00485 // If this is a tentative add, just drop it, otherwise 00486 // note that it's been removed... 00487 00488 if (u >= m_cpaProfile.Count()) 00489 m_cpaAdds.Remove(u - m_cpaProfile.Count()); 00490 else 00491 m_cuaRemovals.Add(u); 00492 00493 // That's it- just update the display, now... 00494 00495 FillList(DEVLIST_CHANGED); 00496 00497 // explicitly set the position of the current selection 00498 // after the list has been recomputed. 00499 00500 int listsize = m_cpaProfile.Count()+m_cpaAdds.Count()-m_cuaRemovals.Count(); 00501 if (id >= listsize) id = listsize-1; 00502 if (id < 0) id = 0; 00503 SendMessage(m_hwndList, LB_SETCURSEL, id, 0); 00504 00505 return TRUE; 00506 } 00507 } 00508 break; 00509 00510 case LBN_SELCHANGE: { 00511 00512 LRESULT id = SendMessage(m_hwndList, LB_GETCURSEL, 0, 0); 00513 00514 if (id == -1) { 00515 EnableWindow(GetDlgItem(m_hwnd, RemoveButton), FALSE); 00516 } else { 00517 00518 // The Remove button must remain disabled on a monitor 00519 // profile property page if the user isn't the 00520 // Administrator, otherwise enable remove button. 00521 00522 EnableWindow(GetDlgItem(m_hwnd, RemoveButton), !m_bReadOnly); 00523 } 00524 00525 return TRUE; 00526 } 00527 } 00528 00529 return FALSE; 00530 }

BOOL CDeviceProfileManagement::OnInit  )  [virtual]
 

Reimplemented from CPropertyPage.

Reimplemented in CPrinterProfileManagement, CScannerProfileManagement, and CMonitorProfileManagement.

Definition at line 337 of file devprop.cpp.

References BOOL, DEVLIST_ONINIT, CPropertyPage::DisableApplyButton(), FALSE, FillList(), GetDlgItem(), InitList(), m_hwndList, ProfileListControl, CPropertyPage::SettingChanged(), and TRUE.

Referenced by CMonitorProfileManagement::OnInit(), CScannerProfileManagement::OnInit(), and CPrinterProfileManagement::OnInit().

00337 { 00338 00339 InitList(); 00340 00341 m_hwndList = GetDlgItem(m_hwnd, ProfileListControl); 00342 00343 // Fill the profile list box 00344 00345 FillList(DEVLIST_ONINIT); 00346 00347 // Disable apply button as default. 00348 00349 DisableApplyButton(); 00350 00351 // Nothing changed, yet. 00352 00353 SettingChanged(FALSE); 00354 00355 return TRUE; 00356 }

BOOL CDeviceProfileManagement::OnNotify int  idCtrl,
LPNMHDR  pnmh
[virtual]
 

Reimplemented from CPropertyPage.

Reimplemented in CPrinterProfileManagement, and CMonitorProfileManagement.

Definition at line 534 of file devprop.cpp.

References BOOL, CUintArray::Count(), CProfileArray::Count(), CPropertyPage::DisableApplyButton(), FALSE, FillList(), InitList(), m_cpaAdds, m_cpaProfile, m_csDevice, m_cuaRemovals, OnNotify(), CProfileArray::Remove(), CPropertyPage::SettingChanged(), SetWindowLongPtr(), and TRUE.

Referenced by OnNotify().

00534 { 00535 00536 switch (pnmh -> code) { 00537 00538 case PSN_APPLY: 00539 00540 DisableApplyButton(); 00541 00542 if (SettingChanged()) { 00543 00544 // Apply the changes the user has made... 00545 00546 SettingChanged(FALSE); 00547 00548 while (m_cpaAdds.Count()) { 00549 if (!m_cpaAdds[0] -> IsInstalled()) { 00550 m_cpaAdds[0] -> Install(); 00551 } 00552 m_cpaAdds[0] -> Associate(m_csDevice); 00553 m_cpaAdds.Remove(0); 00554 } 00555 00556 // Now do the removals (actually just dissociations) 00557 00558 while (m_cuaRemovals.Count()) { 00559 m_cpaProfile[m_cuaRemovals[0]] -> Dissociate(m_csDevice); 00560 m_cuaRemovals.Remove(0); 00561 } 00562 00563 InitList(); 00564 FillList(); 00565 00566 SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, PSNRET_NOERROR); 00567 } 00568 00569 return TRUE; 00570 } 00571 00572 return FALSE; 00573 }


Member Data Documentation

BOOL CDeviceProfileManagement::m_bCMYK [protected]
 

Definition at line 80 of file devprop.h.

Referenced by CDeviceProfileManagement(), and OnCommand().

BOOL CDeviceProfileManagement::m_bReadOnly [protected]
 

Definition at line 81 of file devprop.h.

Referenced by CDeviceProfileManagement(), FillList(), and OnCommand().

CProfileArray CDeviceProfileManagement::m_cpaAdds [protected]
 

Definition at line 76 of file devprop.h.

Referenced by FillList(), InitList(), OnCommand(), and OnNotify().

CProfileArray CDeviceProfileManagement::m_cpaProfile [protected]
 

Definition at line 77 of file devprop.h.

Referenced by FillList(), InitList(), OnCommand(), and OnNotify().

CString CDeviceProfileManagement::m_csDevice [protected]
 

Definition at line 78 of file devprop.h.

Referenced by CDeviceProfileManagement(), InitList(), OnCommand(), and OnNotify().

CUintArray CDeviceProfileManagement::m_cuaRemovals [protected]
 

Definition at line 75 of file devprop.h.

Referenced by FillList(), InitList(), OnCommand(), and OnNotify().

DWORD CDeviceProfileManagement::m_dwType [private]
 

Definition at line 71 of file devprop.h.

Referenced by CDeviceProfileManagement(), and OnCommand().

HWND CDeviceProfileManagement::m_hwndList [protected]
 

Definition at line 79 of file devprop.h.

Referenced by FillList(), OnCommand(), and OnInit().


The documentation for this class was generated from the following files:
Generated on Sat May 15 19:46:27 2004 for test by doxygen 1.3.7