test: propdlg.cpp Source File

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

# propdlg.cpp

Go to the documentation of this file.

    00001 /******************************************************************************
    00002
    00003   Source File: Property Dialogs.CPP
    00004
    00005   Implements the dialogs used in the Profile Management UI.
    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    <stdlib.h>
    00020 #include    "Resource.H"
    00021
    00022 //  CInstallPage member functions
    00023
    00024 //  Class constructor
    00025
    00026 CInstallPage::CInstallPage(CProfilePropertySheet *pcpps) :
    00027     CDialog(pcpps -> Instance(),
    00028         pcpps -> Profile().IsInstalled() ? UninstallPage : InstallPage,
    00029         pcpps -> Window()), m_cppsBoss(*pcpps){ }
    00030
    00031 CInstallPage::~CInstallPage() {}
    00032
    00033 //  OnInit function- this initializes the property page
    00034
    00035 BOOL    CInstallPage::OnInit() {
    00036
    00037     SetDlgItemText(m_hwnd, ProfileNameControl, m_cppsBoss.Profile().GetName());
    00038     if  (m_cppsBoss.Profile().IsInstalled())
    00039         CheckDlgButton(m_hwnd, DeleteFileControl,
    00040             m_cppsBoss.DeleteIsOK() ? BST_CHECKED : BST_UNCHECKED);
    00041
    00042     return  TRUE;
    00043 }
    00044
    00045 BOOL    CInstallPage::OnCommand(WORD wNotifyCode, WORD wid, HWND hwndCtl) {
    00046     switch  (wid) {
    00047         case    DeleteFileControl:
    00048
    00049             if  (wNotifyCode == BN_CLICKED) {
    00050                 m_cppsBoss.DeleteOnUninstall(
    00051                     IsDlgButtonChecked(m_hwnd, DeleteFileControl) ==
    00052                         BST_CHECKED);
    00053                 return  TRUE;
    00054             }
    00055
    00056             break;
    00057
    00058         case    ProfileNameControl:
    00059             if  (wNotifyCode == EN_SETFOCUS) {
    00060                 //  We don't want the entire string selected and scrolled
    00061                 SendDlgItemMessage(m_hwnd, ProfileNameControl, EM_SETSEL,
    00062                     0, 0);
    00063                 return  TRUE;
    00064             }
    00065             break;
    00066     }
    00067
    00068     return  FALSE;
    00069 }
    00070
    00071 //  CAdvancedPage member functions
    00072
    00073 CAdvancedPage::CAdvancedPage(CProfilePropertySheet *pcpps) :
    00074     CDialog(pcpps -> Instance(), AdvancedPage, pcpps -> Window()),
    00075         m_cppsBoss(*pcpps){ }
    00076
    00077 //  Class destructor
    00078
    00079 CAdvancedPage::~CAdvancedPage() {}
    00080
    00081 //  Update private function- fill the list box, and set all the buttons
    00082 //  properly.
    00083
    00084 void    CAdvancedPage::Update() {
    00085
    00086     //  Add the associations to the list
    00087
    00088     SendDlgItemMessage(m_hwnd, DeviceListControl, LB_RESETCONTENT, 0, 0);
    00089
    00090     for (unsigned u = m_cppsBoss.AssociationCount(); u--; ) {
    00091         int iItem = SendDlgItemMessage(m_hwnd, DeviceListControl, LB_ADDSTRING,
    00092             0, (LPARAM) m_cppsBoss.DisplayName(u));
    00093         SendDlgItemMessage(m_hwnd, DeviceListControl, LB_SETITEMDATA, iItem,
    00094             (LPARAM) m_cppsBoss.Association(u));
    00095     }
    00096
    00097     //  If there are no associations, disable the Remove Devices button
    00098
    00099     EnableWindow(GetDlgItem(m_hwnd, RemoveDeviceButton),
    00100         m_cppsBoss.Profile().AssociationCount());
    00101
    00102     //  If there are no devices, or all are associated, disable the Add
    00103     //  Devices button.
    00104
    00105     EnableWindow(GetDlgItem(m_hwnd, AddDeviceButton),
    00106         m_cppsBoss.Profile().DeviceCount() &&
    00107             m_cppsBoss.Profile().DeviceCount() > m_cppsBoss.AssociationCount());
    00108 }
    00109
    00110 //  OnInit function- this initializes the property page
    00111
    00112 BOOL    CAdvancedPage::OnInit() {
    00113
    00114     SetDlgItemText(m_hwnd, ProfileNameControl, m_cppsBoss.Profile().GetName());
    00115
    00116     //  Add the associations to the list, etc.
    00117
    00118     Update();
    00119     return  TRUE;
    00120 }
    00121
    00122 //  OnCommand override- handles control notifications
    00123
    00124 BOOL    CAdvancedPage::OnCommand(WORD wNotifyCode, WORD wid, HWND hwndCtl) {
    00125
    00126     switch  (wid) {
    00127
    00128         case    AddDeviceButton:
    00129
    00130             if  (wNotifyCode == BN_CLICKED) {
    00131                 CAddDeviceDialog    cadd(m_cppsBoss, m_hwnd);
    00132                 Update();
    00133                 return  TRUE;
    00134             }
    00135             break;
    00136
    00137         case    RemoveDeviceButton:
    00138
    00139             if  (wNotifyCode == BN_CLICKED) {
    00140
    00141                 int i = SendDlgItemMessage(m_hwnd, DeviceListControl,
    00142                     LB_GETCURSEL, 0, 0);
    00143
    00144                 if  (i == -1)
    00145                     return  TRUE;
    00146
    00147                 unsigned uItem = SendDlgItemMessage(m_hwnd, DeviceListControl,
    00148                     LB_GETITEMDATA, i, 0);
    00149                 m_cppsBoss.Dissociate(uItem);
    00150                 Update();
    00151                 return  TRUE;
    00152             }
    00153             break;
    00154
    00155         case    DeviceListControl:
    00156             switch  (wNotifyCode) {
    00157
    00158                 case    LBN_SELCHANGE:
    00159                     EnableWindow(GetDlgItem(m_hwnd, RemoveDeviceButton),
    00160                         -1 != SendMessage(hwndCtl, LB_GETCURSEL, 0, 0));
    00161                     return  TRUE;
    00162             }
    00163             break;
    00164     }
    00165
    00166     return  FALSE;
    00167 }
    00168
    00169
    00170 //  CAddDeviceDialog class constructor
    00171
    00172 CAddDeviceDialog::CAddDeviceDialog(CProfilePropertySheet& cpps,
    00173                                    HWND hwndParent) :
    00174     CDialog(cpps.Instance(), AddDeviceDialog, hwndParent), m_cppsBoss(cpps) {
    00175     DoModal();
    00176 }
    00177
    00178 //  Dialog Initialization routine
    00179
    00180 BOOL    CAddDeviceDialog::OnInit() {
    00181
    00182     CProfile&   cpThis = m_cppsBoss.Profile();
    00183     m_hwndList = GetDlgItem(m_hwnd, DeviceListControl);
    00184     m_hwndButton = GetDlgItem(m_hwnd, AddDeviceButton);
    00185
    00186     //  This must not list associated (tentatively) devices, per the spec
    00187
    00188     for (unsigned uDevice = 0; uDevice < cpThis.DeviceCount(); uDevice++) {
    00189         for (unsigned u = 0; u < m_cppsBoss.AssociationCount(); u++)
    00190             if  (uDevice == m_cppsBoss.Association(u))
    00191                 break;
    00192         if  (u < m_cppsBoss.AssociationCount())
    00193             continue;   //  Don't insert this one...
    00194         int idItem = SendMessage(m_hwndList, LB_ADDSTRING, 0,
    00195             (LPARAM) cpThis.DisplayName(uDevice));
    00196         SendMessage(m_hwndList, LB_SETITEMDATA, idItem, (LPARAM) uDevice);
    00197     }
    00198
    00199     if  (SendMessage(m_hwndList, LB_GETCOUNT, 0, 0))
    00200         SendMessage(m_hwndList, LB_SETCURSEL, 0, 0);
    00201
    00202     EnableWindow(m_hwndButton, -1 !=
    00203         SendMessage(m_hwndList, LB_GETCURSEL, 0, 0));
    00204     return  TRUE;
    00205 }
    00206
    00207 //  Dialog notification handler
    00208
    00209 BOOL    CAddDeviceDialog::OnCommand(WORD wNotification, WORD wid,
    00210                                     HWND hwndControl){
    00211
    00212     switch  (wNotification) {
    00213
    00214         case    LBN_SELCHANGE:
    00215             EnableWindow(m_hwndButton, -1 !=
    00216                 SendMessage(m_hwndList, LB_GETCURSEL, 0, 0));
    00217             return  TRUE;
    00218
    00219         case    BN_CLICKED:
    00220             if  (wid == AddDeviceButton) {
    00221
    00222                 int i = SendMessage(m_hwndList, LB_GETCURSEL, 0, 0);
    00223
    00224                 if  (i == -1)
    00225                     return  TRUE;
    00226
    00227                 unsigned uItem = (unsigned) SendMessage(m_hwndList,
    00228                     LB_GETITEMDATA, i, 0);
    00229                 m_cppsBoss.Associate(uItem);
    00230             }
    00231             break;
    00232
    00233         case    LBN_DBLCLK:
    00234             return  OnCommand(BN_CLICKED, AddDeviceButton, m_hwndButton);
    00235     }
    00236
    00237     return  CDialog::OnCommand(wNotification, wid, hwndControl);
    00238 }