test: CPrinterProfileManagement class Reference

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

# CPrinterProfileManagement Class Reference

`#include <devprop.h>`

Inheritance diagram for CPrinterProfileManagement:

List of all members.

## Public Member Functions

| CPrinterProfileManagement (LPCTSTR lpstrName, HINSTANCE hiWhere)
| ~CPrinterProfileManagement ()
virtual BOOL | OnInit ()
virtual BOOL | OnCommand (WORD wNotifyCode, WORD wid, HWND hwndCtl)
virtual BOOL | OnNotify (int idCtrl, LPNMHDR pnmh)
virtual BOOL | OnHelp (LPHELPINFO pHelp)
virtual BOOL | OnContextMenu (HWND hwnd)

## Protected Member Functions

virtual void | InitList ()
virtual void | FillList (DWORD dwFlags=0)

## Protected Attributes

unsigned | m_uDefault
BOOL | m_bManualMode
BOOL | m_bAdminAccess
BOOL | m_bLocalPrinter

## Constructor & Destructor Documentation

CPrinterProfileManagement::CPrinterProfileManagement | ( | LPCTSTR | lpstrName,
|  | HINSTANCE | hiWhere
| ) |

Definition at line 814 of file devprop.cpp.

References CPrinterProfileManagement(), and PrinterUI.

Referenced by CPrinterProfileManagement().

    00815                                                                         :
    00816     CDeviceProfileManagement(lpstrName, hiWhere, PrinterUI, CLASS_PRINTER) {
    00817 }

CPrinterProfileManagement::~CPrinterProfileManagement | ( |  | ) | `[inline]`

Definition at line 141 of file devprop.h.

    00141 {}

## Member Function Documentation

void CPrinterProfileManagement::FillList | ( | DWORD | dwFlags = `0` | ) | `[protected, virtual]`

Reimplemented from CDeviceProfileManagement.

Definition at line 741 of file devprop.cpp.

References CUintArray::Count(), CProfileArray::Count(), DefaultButton, DefaultProfile, DEVLIST_NOSELECT, DEVLIST_ONINIT, dwFlags, EnableWindow(), FillList(), GetDlgItem(), CString::Load(), m_bAdminAccess, m_bManualMode, m_uDefault, NoProfileString, SendMessage(), and SetDlgItemText().

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

    00741                                                          {
    00742
    00743     //  If we are initializing list box, we want to put focus on
    00744     //  "default" profile. here we won't below FillList set focus
    00745     //  to first one.
    00746
    00747     if (dwFlags & DEVLIST_ONINIT) {
    00748         dwFlags |= DEVLIST_NOSELECT;
    00749     }
    00750
    00751     CDeviceProfileManagement::FillList(dwFlags);
    00752
    00753     //  There is either no default profile, an existing profile is the
    00754     //  default, or a newly selected one is.  Some people just like the
    00755     //  selection operator.
    00756
    00757     //  if there is only 1 profile in list box, we treat it as default profile.
    00758
    00759     if (SendMessage(m_hwndList,LB_GETCOUNT,0,0) == 1) {
    00760         m_uDefault = (unsigned)SendMessage(m_hwndList, LB_GETITEMDATA, 0, 0);
    00761     }
    00762
    00763     if (m_uDefault == -1) {
    00764
    00765         // There is no profile associated for this device.
    00766
    00767         CString csNoProfile;
    00768         csNoProfile.Load(NoProfileString);
    00769         SetDlgItemText(m_hwnd, DefaultProfile, csNoProfile);
    00770
    00771     } else {
    00772
    00773         // If the default has been deleted, set default as last in list.
    00774
    00775         if (m_uDefault >= (m_cpaProfile.Count() + m_cpaAdds.Count())) {
    00776
    00777             m_uDefault = (m_cpaProfile.Count() + m_cpaAdds.Count()) - 1;
    00778         }
    00779
    00780         // Put default profile name in UI.
    00781
    00782         CProfile *pcpDefault = (m_uDefault < m_cpaProfile.Count()) ? \
    00783                                            m_cpaProfile[m_uDefault] : \
    00784                                            m_cpaAdds[m_uDefault - m_cpaProfile.Count()];
    00785
    00786         SetDlgItemText(m_hwnd, DefaultProfile, pcpDefault -> GetName());
    00787
    00788         LRESULT idSelect = SendMessage(m_hwndList, LB_FINDSTRINGEXACT,
    00789                                    (WPARAM) -1, (LPARAM) (LPCTSTR) pcpDefault -> GetName());
    00790
    00791         // if could not find, just select first item.
    00792
    00793         if (idSelect == LB_ERR) {
    00794             idSelect = 0;
    00795         }
    00796
    00797         // Select it.
    00798
    00799         SendMessage(m_hwndList, LB_SETCURSEL, idSelect, 0);
    00800     }
    00801
    00802     //  03-08-1997  Bob_Kjelgaard@Prodigy.Net   Memphis RAID 18420
    00803     //  Disable the Default button if there aren't any profiles
    00804
    00805     if (m_bManualMode && m_bAdminAccess) {
    00806         EnableWindow(GetDlgItem(m_hwnd, DefaultButton),
    00807                      m_cpaAdds.Count() + m_cpaProfile.Count() - m_cuaRemovals.Count());
    00808     }
    00809 }

void CPrinterProfileManagement::InitList | ( |  | ) | `[protected, virtual]`

Reimplemented from CDeviceProfileManagement.

Definition at line 732 of file devprop.cpp.

References CProfileArray::Count(), CDeviceProfileManagement::InitList(), and m_uDefault.

Referenced by OnNotify().

    00732                                             {
    00733
    00734     CDeviceProfileManagement::InitList();
    00735
    00736     m_uDefault = m_cpaProfile.Count() ? 0 : (unsigned) -1;
    00737 }

BOOL CPrinterProfileManagement::OnCommand | ( | WORD | wNotifyCode,
|  | WORD | wid,
|  | HWND | hwndCtl
| ) | `[virtual]`

Reimplemented from CDeviceProfileManagement.

Definition at line 950 of file devprop.cpp.

References AskRemoveDefault, AutoSelButton, BOOL, CProfileArray::Count(), DefaultButton, DEVLIST_CHANGED, CPropertyPage::EnableApplyButton(), EnableWindow(), FALSE, FillList(), GetDlgItem(), m_bManualMode, m_uDefault, ManualSelButton, OnCommand(), RemoveButton, SendMessage(), CPropertyPage::SettingChanged(), and TRUE.

Referenced by OnCommand().

    00951                                                            {
    00952
    00953     switch  (wNotifyCode) {
    00954
    00955         case    LBN_DBLCLK: {
    00956
    00957             //  Retrieve the ID of the new default profile
    00958             //  only accept dblclk changes if the dialog
    00959             //  is not read only - i.e. user is admin
    00960
    00961             if  (m_bManualMode) {
    00962
    00963                 int id = (int)SendMessage(m_hwndList, LB_GETCURSEL, 0, 0);
    00964                 m_uDefault = (unsigned)SendMessage(m_hwndList, LB_GETITEMDATA, id, 0);
    00965
    00966                 //  Change has been made, update the list
    00967
    00968                 FillList(DEVLIST_CHANGED);
    00969             }
    00970
    00971             return  TRUE;
    00972         }
    00973
    00974         case    BN_CLICKED:
    00975
    00976             switch  (wid) {
    00977
    00978                 case    AutoSelButton:
    00979                 case    ManualSelButton: {
    00980
    00981                     // How many profile in listbox ?
    00982
    00983                     LRESULT itemCount = SendMessage(m_hwndList, LB_GETCOUNT, 0, 0);
    00984                     if (itemCount == LB_ERR) itemCount = 0;
    00985
    00986                     m_bManualMode = (wid == ManualSelButton) ? TRUE : FALSE;
    00987
    00988                     //  Only with manual mode, these controls are enabled.
    00989
    00990                     EnableWindow(GetDlgItem(m_hwnd, DefaultButton), m_bManualMode && itemCount);
    00991
    00992                     //  Configuarion has been changed, enable apply button.
    00993
    00994                     EnableApplyButton();
    00995                     SettingChanged(TRUE);
    00996
    00997                     return TRUE;
    00998                 }
    00999
    01000                 case    RemoveButton: {
    01001
    01002                     //  Make sure we've tracked the default profile correctly
    01003                     //  when a profile is removed.
    01004                     //  All cases break, because we then want the base class to
    01005                     //  process this message.
    01006
    01007                     LRESULT id = SendMessage(m_hwndList, LB_GETCURSEL, 0, 0);
    01008
    01009                     unsigned uTarget = (unsigned)SendMessage(m_hwndList, LB_GETITEMDATA,
    01010                         id, 0);
    01011
    01012                     if  (uTarget > m_uDefault || m_uDefault == (unsigned) -1)
    01013                         break;  //  Nothing here to worry about
    01014
    01015                     if  (m_uDefault == uTarget) {
    01016
    01017                         if (CGlobals::ReportEx(AskRemoveDefault, m_hwnd, FALSE,
    01018                                                MB_YESNO|MB_ICONEXCLAMATION,0) == IDYES) {
    01019
    01020                             //  The default has been deleted- the profile
    01021                             //  at the top of monitor profile list will be
    01022                             //  made the default profile, if we have
    01023
    01024                             LRESULT itemCount = SendMessage(m_hwndList, LB_GETCOUNT, 0, 0);
    01025
    01026                             if ((itemCount != LB_ERR) && (itemCount > 1)) {
    01027                                 m_uDefault = (unsigned)SendMessage(m_hwndList, LB_GETITEMDATA, 0, 0);
    01028                                 if (m_uDefault == uTarget) {
    01029                                     m_uDefault = (unsigned)SendMessage(m_hwndList, LB_GETITEMDATA, 1, 0);
    01030                                 }
    01031                             } else {
    01032                                 m_uDefault = -1;
    01033                             }
    01034
    01035                             break;
    01036                         } else {
    01037                             return TRUE; // opration cancelled.
    01038                         }
    01039                     }
    01040
    01041                     if  (uTarget < m_cpaProfile.Count())
    01042                         break;  // We're fine
    01043
    01044                     //  Must be an added profile below us in the list was
    01045                     //  zapped- we need to decrement ourselves.
    01046
    01047                     m_uDefault--;
    01048                     break;
    01049                 }
    01050
    01051                 case    DefaultButton: {
    01052
    01053                     LRESULT id = SendMessage(m_hwndList, LB_GETCURSEL, 0, 0);
    01054
    01055                     m_uDefault = (unsigned)SendMessage(m_hwndList, LB_GETITEMDATA, id, 0);
    01056
    01057                     //  Change has been made, update the list
    01058
    01059                     FillList(DEVLIST_CHANGED);
    01060
    01061                     return  TRUE;
    01062                 }
    01063             }
    01064
    01065         //  Deliberate fall-through (use a break if you add a case here)
    01066     }
    01067
    01068     //  Use common command handling if not handled above
    01069
    01070     return  CDeviceProfileManagement::OnCommand(wNotifyCode, wid, hwndCtl);
    01071 }

BOOL CPrinterProfileManagement::OnContextMenu | ( | HWND | hwnd | ) | `[virtual]`

Reimplemented from CPropertyPage.

Definition at line 1186 of file devprop.cpp.

References BOOL, OnContextMenu(), PrinterUIHelpIds, TRUE, and WINDOWS_HELP_FILE.

Referenced by OnContextMenu().

    01186                                                           {
    01187
    01188     WinHelp(hwnd, WINDOWS_HELP_FILE,
    01189             HELP_CONTEXTMENU, (ULONG_PTR) (LPSTR) PrinterUIHelpIds);
    01190
    01191     return (TRUE);
    01192 }

BOOL CPrinterProfileManagement::OnHelp | ( | LPHELPINFO | pHelp | ) | `[virtual]`

Reimplemented from CPropertyPage.

Definition at line 1176 of file devprop.cpp.

References BOOL, OnHelp(), PrinterUIHelpIds, TRUE, and WINDOWS_HELP_FILE.

Referenced by OnHelp().

    01176                                                           {
    01177
    01178     if (pHelp->iContextType == HELPINFO_WINDOW) {
    01179         WinHelp((HWND) pHelp->hItemHandle, WINDOWS_HELP_FILE,
    01180                 HELP_WM_HELP, (ULONG_PTR) (LPSTR) PrinterUIHelpIds);
    01181     }
    01182
    01183     return (TRUE);
    01184 }

BOOL CPrinterProfileManagement::OnInit | ( |  | ) | `[virtual]`

Reimplemented from CDeviceProfileManagement.

Definition at line 822 of file devprop.cpp.

References AddButton, AutoSelButton, BOOL, BYTE, CheckDlgButton(), DefaultButton, DefaultProfile, DefaultProfileText, DWORD, EnableWindow(), FALSE, GetDlgItem(), InternalGetDeviceConfig(), m_bAdminAccess, m_bLocalPrinter, m_bManualMode, ManualSelButton, MAX_PATH, NULL, CDeviceProfileManagement::OnInit(), PBYTE, pd, RemoveButton, SendMessage(), SetFocus, and TRUE.

    00822                                           {
    00823
    00824     //  Call the base class routine first, as it does most of the work...
    00825
    00826     CDeviceProfileManagement::OnInit();
    00827
    00828     DWORD dwSize = sizeof(DWORD);
    00829
    00830     //  Query current mode.
    00831
    00832     if (!InternalGetDeviceConfig((LPCTSTR)m_csDevice, CLASS_PRINTER,
    00833                                  MSCMS_PROFILE_ENUM_MODE, &m_bManualMode, &dwSize)) {
    00834
    00835         //  Auto selection mode as default.
    00836
    00837         m_bManualMode = FALSE;
    00838     }
    00839
    00840     //  Now, see if we have sufficient authority to administer the printer
    00841
    00842     HANDLE  hPrinter;
    00843     PRINTER_DEFAULTS    pd = {NULL, NULL, PRINTER_ACCESS_ADMINISTER};
    00844
    00845     m_bAdminAccess  = TRUE;
    00846     m_bLocalPrinter = TRUE;
    00847
    00848     if  (OpenPrinter(const_cast<LPTSTR> ((LPCTSTR) m_csDevice), &hPrinter, &pd)) {
    00849
    00850         //  We can administer the printer- proceed in the normal way.
    00851
    00852 #if !defined(_WIN95_)
    00853
    00854         //  If the printer is "Network Printer", we don't allow user to install
    00855         //  or uninstall color profile.
    00856
    00857         BYTE  StackPrinterData[sizeof(PRINTER_INFO_4)+MAX_PATH*2];
    00858         PBYTE pPrinterData = StackPrinterData;
    00859         BOOL  bSuccess = TRUE;
    00860         DWORD dwReturned;
    00861
    00862         if (!GetPrinter(hPrinter, 4, pPrinterData, sizeof(StackPrinterData), &dwReturned)) {
    00863
    00864             if ((GetLastError() == ERROR_INSUFFICIENT_BUFFER) &&
    00865                 (pPrinterData = (PBYTE) LocalAlloc(LPTR, dwReturned))) {
    00866
    00867                 if (GetPrinter(hPrinter, 4, pPrinterData, dwReturned, &dwReturned)) {
    00868
    00869                     bSuccess = TRUE;
    00870
    00871                 }
    00872             }
    00873
    00874         } else {
    00875
    00876             bSuccess = TRUE;
    00877         }
    00878
    00879         if (bSuccess)
    00880         {
    00881             m_bLocalPrinter = ((PRINTER_INFO_4 *)pPrinterData)->pServerName ? FALSE : TRUE;
    00882         }
    00883         else
    00884         {
    00885             m_bAdminAccess = FALSE;
    00886         }
    00887
    00888         if (pPrinterData && (pPrinterData != StackPrinterData))
    00889         {
    00890             LocalFree(pPrinterData);
    00891         }
    00892
    00893 #endif // !defined(_WIN95_)
    00894
    00895         ClosePrinter(hPrinter);
    00896
    00897     } else {
    00898
    00899         m_bAdminAccess = FALSE;
    00900     }
    00901
    00902     // How many profile in listbox ?
    00903
    00904     LRESULT itemCount = SendMessage(m_hwndList, LB_GETCOUNT, 0, 0);
    00905     if (itemCount == LB_ERR) itemCount = 0;
    00906
    00907     //  make sure the ancestor list code behaves correctly.
    00908     //  You need Admin Access and a Local Printer to be able to add/remove profiles
    00909
    00910     m_bReadOnly = !(m_bAdminAccess && m_bLocalPrinter);
    00911
    00912     //  Enable/Disable the controls (if needed)
    00913
    00914     CheckDlgButton(m_hwnd, AutoSelButton, m_bManualMode ? BST_UNCHECKED : BST_CHECKED);
    00915     CheckDlgButton(m_hwnd, ManualSelButton, m_bManualMode ? BST_CHECKED : BST_UNCHECKED);
    00916
    00917     //  Only administrator can change 'auto','manual' configuration.
    00918
    00919     EnableWindow(GetDlgItem(m_hwnd, AutoSelButton), m_bAdminAccess && m_bLocalPrinter);
    00920     EnableWindow(GetDlgItem(m_hwnd, ManualSelButton), m_bAdminAccess && m_bLocalPrinter);
    00921
    00922     //  Only administrator and printer is at local, can install/uninstall color profile.
    00923
    00924     EnableWindow(GetDlgItem(m_hwnd, AddButton), m_bAdminAccess && m_bLocalPrinter);
    00925     EnableWindow(GetDlgItem(m_hwnd, RemoveButton), m_bAdminAccess && m_bLocalPrinter && itemCount);
    00926
    00927     EnableWindow(m_hwndList, m_bAdminAccess);
    00928     EnableWindow(GetDlgItem(m_hwnd, DefaultProfileText), m_bAdminAccess);
    00929     EnableWindow(GetDlgItem(m_hwnd, DefaultProfile), m_bAdminAccess);
    00930
    00931     //  Only with manual mode, these controls are enabled.
    00932
    00933     EnableWindow(GetDlgItem(m_hwnd, DefaultButton), m_bAdminAccess && m_bManualMode
    00934                                                          && m_bLocalPrinter && itemCount);
    00935
    00936     if (!m_bAdminAccess) {
    00937
    00938         //  Set the focus to the OK button
    00939
    00940         SetFocus(GetDlgItem(m_hwndSheet, IDOK));
    00941         return  FALSE;  //  Because we moved the focus!
    00942     }
    00943
    00944     return TRUE;
    00945 }

BOOL CPrinterProfileManagement::OnNotify | ( | int | idCtrl,
|  | LPNMHDR | pnmh
| ) | `[virtual]`

Reimplemented from CDeviceProfileManagement.

Definition at line 1075 of file devprop.cpp.

References BOOL, CUintArray::Count(), CProfileArray::Count(), CPropertyPage::DisableApplyButton(), DWORD, FALSE, FillList(), InitList(), InternalSetDeviceConfig(), m_bManualMode, m_uDefault, NoDefaultProfile, OnNotify(), CPropertyPage::SettingChanged(), SetWindowLongPtr(), and TRUE.

Referenced by OnNotify().

    01075                                                                     {
    01076
    01077     switch  (pnmh -> code) {
    01078
    01079         case    PSN_APPLY: {
    01080
    01081             DisableApplyButton();
    01082
    01083             //  If nothing changed, nothing need to do.
    01084
    01085             if (!SettingChanged())
    01086                 return TRUE;
    01087
    01088             if (m_bManualMode) {
    01089
    01090                 //  If the user hasn't selected a default, and we have
    01091                 //  associated profiles, then we can't allow this.
    01092
    01093                 //  03-08-1997  A-RobKj Fix for Memphis RAID 18416- if there's
    01094                 //  only one profile left, then it must be the default.
    01095
    01096                 if  (m_uDefault == (unsigned) -1 && (m_cpaAdds.Count() +
    01097                      m_cpaProfile.Count() - m_cuaRemovals.Count()) > 1) {
    01098
    01099                     CGlobals::Report(NoDefaultProfile, m_hwndSheet);
    01100                     SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
    01101                     break;
    01102                 }
    01103
    01104                 //  !!! This behavior is hardly depend on EnumColorProfiles() API !!!
    01105
    01106                 //  OK, if the default profile has changed, we have to delete default
    01107                 //  profile associations, and do the association for default profile
    01108                 //  in "last".
    01109
    01110                 //  Let the base class handle the cases where the default hasn't
    01111                 //  changed, or we started with no profiles and still have none.
    01112                 //
    01113                 //  03-08-1997  Sleazy code note.  The case where no default is
    01114                 //  selected but only one is assigned will now fall here.  Since the
    01115                 //  default happens to be the "last", and there only is one, letting
    01116                 //  the base class handle it is not a problem.  The list filling
    01117                 //  code will take care of the rest for us.
    01118
    01119                 if  (m_uDefault == (unsigned) -1) break;
    01120
    01121                 //  Remove default first (if default is associated), then associate later.
    01122
    01123                 if  (m_uDefault < m_cpaProfile.Count())
    01124                     m_cpaProfile[m_uDefault] -> Dissociate(m_csDevice);
    01125
    01126                 //  Now do the other removals (actually just dissociations)
    01127
    01128                 for (unsigned u = 0; u < m_cuaRemovals.Count(); u++) {
    01129                     m_cpaProfile[m_cuaRemovals[u]] -> Dissociate(m_csDevice);
    01130                 }
    01131
    01132                 //  Add in the new ones
    01133
    01134                 for (u = 0; u < m_cpaAdds.Count(); u++) {
    01135                     if  (m_uDefault >= m_cpaProfile.Count())
    01136                         if  (u == (m_uDefault - m_cpaProfile.Count()))
    01137                             continue;   // this is default, will be done later
    01138
    01139                     //  OK, add it back in...
    01140                     m_cpaAdds[u] -> Associate(m_csDevice);
    01141                 }
    01142
    01143                 //  Finally, associate back default profile.
    01144
    01145                 if  (m_uDefault < m_cpaProfile.Count())
    01146                     m_cpaProfile[m_uDefault] -> Associate(m_csDevice);
    01147                 else
    01148                     m_cpaAdds[m_uDefault - m_cpaProfile.Count()] -> Associate(m_csDevice);
    01149
    01150                 //  Update the various working structures...
    01151
    01152                 InitList();
    01153                 FillList();
    01154
    01155                 SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, PSNRET_NOERROR);
    01156
    01157                 //  Now, we have updated settings.
    01158
    01159                 SettingChanged(FALSE);
    01160             }
    01161
    01162             // Update "auto/manual" status.
    01163
    01164             InternalSetDeviceConfig((LPCTSTR)m_csDevice, CLASS_PRINTER,
    01165                                     MSCMS_PROFILE_ENUM_MODE, &m_bManualMode, sizeof(DWORD));
    01166         }
    01167     }
    01168
    01169     //  Let the base class handle everything else
    01170
    01171     return  CDeviceProfileManagement::OnNotify(idCtrl, pnmh);
    01172 }

## Member Data Documentation

BOOL CPrinterProfileManagement::m_bAdminAccess`[protected]`

| Definition at line 132 of file devprop.h. Referenced by FillList(), and OnInit().

BOOL CPrinterProfileManagement::m_bLocalPrinter`[protected]`

| Definition at line 133 of file devprop.h. Referenced by OnInit().

BOOL CPrinterProfileManagement::m_bManualMode`[protected]`

| Definition at line 131 of file devprop.h. Referenced by FillList(), OnCommand(), OnInit(), and OnNotify().

unsigned CPrinterProfileManagement::m_uDefault`[protected]`

| Definition at line 130 of file devprop.h. Referenced by FillList(), InitList(), OnCommand(), and OnNotify().

The documentation for this class was generated from the following files:

- devprop.h
- devprop.cpp