test: profprop.cpp Source File

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

# profprop.cpp

Go to the documentation of this file.

    00001 /******************************************************************************
    00002
    00003   Source File:  Profile Property Sheet.CPP
    00004
    00005   This implements the code for the profile property sheet.
    00006
    00007   Copyright (c) 1996 by Microsoft Corporation
    00008
    00009   A Pretty Penny Enterprises Production
    00010
    00011   Change History:
    00012
    00013   11-01-96  a-robkj@microsoft.com- original version
    00014
    00015 ******************************************************************************/
    00016
    00017 #include    "ICMUI.H"
    00018
    00019 #include    "Resource.H"
    00020
    00021 //  Private ConstructAssociations function- this constructs the list of
    00022 //  tentative associations- this starts out as the true list from the profile
    00023 //  object, but reflects all adds and deletes made on the Advanced page.
    00024
    00025 void    CProfilePropertySheet::ConstructAssociations() {
    00026
    00027     m_cuaAssociate.Empty(); //  Clean it up!
    00028
    00029     for (unsigned u = 0; u < m_cpTarget.AssociationCount(); u++) {
    00030         for (unsigned uDelete = 0;
    00031              uDelete < m_cuaDelete.Count();
    00032              uDelete++)
    00033
    00034             if  (m_cuaDelete[uDelete] == m_cpTarget.Association(u))
    00035                 break;
    00036
    00037         if  (uDelete == m_cuaDelete.Count())    //  Not yet deleted
    00038             m_cuaAssociate.Add(m_cpTarget.Association(u));
    00039     }
    00040
    00041     //  Now, add any added associations
    00042
    00043     for (u = 0; u < m_cuaAdd.Count(); u++)
    00044         m_cuaAssociate.Add(m_cuaAdd[u]);
    00045 }
    00046
    00047
    00048 //  Class constructor- we use one dialog for the installed case, and another
    00049 //  for the uninstalled one.  This traded code for resource size, since the
    00050 //  two forms are similar enough I can use the same code to handle both.
    00051
    00052 //  This is a tricky constructor- it actually presents the dialog when the
    00053 //  instance is constructed.
    00054
    00055 CProfilePropertySheet::CProfilePropertySheet(HINSTANCE hiWhere,
    00056                                             CProfile& cpTarget) :
    00057     CDialog(hiWhere,
    00058         cpTarget.IsInstalled() ? UninstallInterface : InstallInterface),
    00059         m_cpTarget(cpTarget) {
    00060
    00061     if  (!cpTarget.IsValid()) {
    00062         for (int i = 0; i < sizeof m_pcdPage / sizeof m_pcdPage[0]; i++)
    00063             m_pcdPage[i] = NULL;
    00064
    00065         CGlobals::Report(InvalidProfileString, m_hwndParent);
    00066         return;
    00067     }
    00068
    00069     m_bDelete = FALSE;
    00070     ConstructAssociations();
    00071
    00072     DoModal();
    00073 }
    00074
    00075 //  Class destructor- we have to get rid of the individual pages
    00076
    00077 CProfilePropertySheet::~CProfilePropertySheet() {
    00078     for (int i = 0; i < sizeof m_pcdPage / sizeof (m_pcdPage[0]); i++)
    00079         if  (m_pcdPage[i])
    00080             delete  m_pcdPage[i];
    00081 }
    00082
    00083 //  Public method for noting tentative associations to be added
    00084
    00085 void    CProfilePropertySheet::Associate(unsigned uAdd) {
    00086     //  First, see if it's on the delete list.  If it is, remove it from there
    00087     //  Otherwise, add us to the add list, if it's a new association.
    00088
    00089     for (unsigned u = 0; u < m_cuaDelete.Count(); u++)
    00090         if  (uAdd == m_cuaDelete[u])
    00091             break;
    00092
    00093     if  (u < m_cuaDelete.Count())
    00094         m_cuaDelete.Remove(u);
    00095     else {
    00096         for (u = 0; u < m_cuaAssociate.Count(); u++)
    00097             if  (m_cuaAssociate[u] == uAdd)
    00098                 break;
    00099         if  (u == m_cuaAssociate.Count())
    00100             m_cuaAdd.Add(uAdd);
    00101     }
    00102
    00103     ConstructAssociations();
    00104 }
    00105
    00106 //  Public Method for removing tentative associations
    00107
    00108 void    CProfilePropertySheet::Dissociate(unsigned uRemove) {
    00109     //  First, see if it's on the add list.  If it is, remove it from there
    00110     //  Otherwise, add us to the delete list.
    00111
    00112     for (unsigned u = 0; u < m_cuaAdd.Count(); u++)
    00113         if  (uRemove == m_cuaAdd[u])
    00114             break;
    00115
    00116     if  (u < m_cuaAdd.Count())
    00117         m_cuaAdd.Remove(u);
    00118     else
    00119         m_cuaDelete.Add(uRemove);
    00120
    00121     ConstructAssociations();
    00122 }
    00123
    00124 //  Dialog Initialization override
    00125
    00126 BOOL    CProfilePropertySheet::OnInit() {
    00127
    00128     CString csWork;
    00129     TC_ITEM tciThis = {TCIF_TEXT, 0, 0, NULL, 0, -1, 0};
    00130
    00131     //  We'll begin by determining the bounding rectangle of the client
    00132     //  area of the tab control
    00133
    00134     RECT rcWork;
    00135
    00136     GetWindowRect(GetDlgItem(m_hwnd, TabControl), &m_rcTab);
    00137     GetWindowRect(m_hwnd, &rcWork);
    00138     OffsetRect(&m_rcTab, -rcWork.left, -rcWork.top);
    00139     SendDlgItemMessage(m_hwnd, TabControl, TCM_ADJUSTRECT, FALSE,
    00140         (LPARAM) &m_rcTab);
    00141
    00142     //  Then, we create the classes for the two descendants, and
    00143     //  initialize the first dialog.
    00144
    00145     m_pcdPage[0] = new CInstallPage(this);
    00146     m_pcdPage[1] = new CAdvancedPage(this);
    00147     m_pcdPage[0] -> Create();
    00148     m_pcdPage[0] -> Adjust(m_rcTab);
    00149
    00150     //  Then, initialize the tab control
    00151
    00152     csWork.Load(m_cpTarget.IsInstalled() ?
    00153         ShortUninstallString : ShortInstallString);
    00154
    00155     tciThis.pszText = const_cast<LPTSTR>((LPCTSTR) csWork);
    00156
    00157     SendDlgItemMessage(m_hwnd, TabControl, TCM_INSERTITEM, 0,
    00158         (LPARAM) &tciThis);
    00159
    00160     csWork.Load(AdvancedString);
    00161
    00162     tciThis.pszText = const_cast<LPTSTR>((LPCTSTR) csWork);
    00163
    00164     SendDlgItemMessage(m_hwnd, TabControl, TCM_INSERTITEM, 1,
    00165         (LPARAM) &tciThis);
    00166
    00167     //  Finally, let's set the icons for this little monster...
    00168
    00169     HICON   hi = LoadIcon(m_hiWhere,
    00170         MAKEINTRESOURCE(m_cpTarget.IsInstalled() ?
    00171             DefaultIcon : UninstalledIcon));
    00172
    00173     SendMessage(m_hwnd, WM_SETICON, ICON_BIG, (LPARAM) hi);
    00174
    00175     return  TRUE;   //  We've not set the focus anywhere
    00176 }
    00177
    00178 //  Common control notification override
    00179
    00180 BOOL    CProfilePropertySheet::OnNotify(int idCtrl, LPNMHDR pnmh) {
    00181
    00182     int iPage = !!SendMessage(pnmh -> hwndFrom, TCM_GETCURSEL, 0, 0);
    00183
    00184     switch  (pnmh -> code) {
    00185         case    TCN_SELCHANGING:
    00186
    00187             m_pcdPage[iPage] -> Destroy();
    00188             return  FALSE;      //  Allow the selection to change.
    00189
    00190         case    TCN_SELCHANGE:
    00191
    00192             //  Create the appropriate dialog
    00193
    00194             m_pcdPage[iPage] -> Create();
    00195             m_pcdPage[iPage] -> Adjust(m_rcTab);
    00196
    00197             return  TRUE;
    00198     }
    00199
    00200     return  TRUE;   //  Claim to have handled it (perhaps a bit bogus).
    00201 }
    00202
    00203 //  Control Notification override
    00204
    00205 BOOL    CProfilePropertySheet::OnCommand(WORD wNotifyCode, WORD wid,
    00206                                          HWND hwndControl) {
    00207     switch  (wid) {
    00208
    00209         case    IDOK:
    00210
    00211             if  (wNotifyCode == BN_CLICKED && !m_cpTarget.IsInstalled())
    00212                 m_cpTarget.Install();
    00213             //  Remove any associations we're removing
    00214             while   (m_cuaDelete.Count()) {
    00215                 m_cpTarget.Dissociate(m_cpTarget.Device(m_cuaDelete[0]));
    00216                 m_cuaDelete.Remove(0);
    00217             }
    00218             //  Add any associations we're adding
    00219             while   (m_cuaAdd.Count()) {
    00220                 m_cpTarget.Associate(m_cpTarget.Device(m_cuaAdd[0]));
    00221                 m_cuaAdd.Remove(0);
    00222             }
    00223             break;
    00224
    00225         case    UninstallButton:
    00226
    00227             if  (wNotifyCode == BN_CLICKED)
    00228                 m_cpTarget.Uninstall(m_bDelete);
    00229             break;
    00230     }
    00231
    00232     return  CDialog::OnCommand(wNotifyCode, wid, hwndControl);
    00233 }