Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

238 lines
7.0 KiB

  1. /******************************************************************************
  2. Source File: Property Dialogs.CPP
  3. Implements the dialogs used in the Profile Management UI.
  4. Copyright (c) 1996 by Microsoft Corporation
  5. A Pretty Penny Enterprises Production
  6. Change History:
  7. 11-01-96 a-robkj@microsoft.com- original version
  8. ******************************************************************************/
  9. #include "ICMUI.H"
  10. #include <stdlib.h>
  11. #include "Resource.H"
  12. // CInstallPage member functions
  13. // Class constructor
  14. CInstallPage::CInstallPage(CProfilePropertySheet *pcpps) :
  15. CDialog(pcpps -> Instance(),
  16. pcpps -> Profile().IsInstalled() ? UninstallPage : InstallPage,
  17. pcpps -> Window()), m_cppsBoss(*pcpps){ }
  18. CInstallPage::~CInstallPage() {}
  19. // OnInit function- this initializes the property page
  20. BOOL CInstallPage::OnInit() {
  21. SetDlgItemText(m_hwnd, ProfileNameControl, m_cppsBoss.Profile().GetName());
  22. if (m_cppsBoss.Profile().IsInstalled())
  23. CheckDlgButton(m_hwnd, DeleteFileControl,
  24. m_cppsBoss.DeleteIsOK() ? BST_CHECKED : BST_UNCHECKED);
  25. return TRUE;
  26. }
  27. BOOL CInstallPage::OnCommand(WORD wNotifyCode, WORD wid, HWND hwndCtl) {
  28. switch (wid) {
  29. case DeleteFileControl:
  30. if (wNotifyCode == BN_CLICKED) {
  31. m_cppsBoss.DeleteOnUninstall(
  32. IsDlgButtonChecked(m_hwnd, DeleteFileControl) ==
  33. BST_CHECKED);
  34. return TRUE;
  35. }
  36. break;
  37. case ProfileNameControl:
  38. if (wNotifyCode == EN_SETFOCUS) {
  39. // We don't want the entire string selected and scrolled
  40. SendDlgItemMessage(m_hwnd, ProfileNameControl, EM_SETSEL,
  41. 0, 0);
  42. return TRUE;
  43. }
  44. break;
  45. }
  46. return FALSE;
  47. }
  48. // CAdvancedPage member functions
  49. CAdvancedPage::CAdvancedPage(CProfilePropertySheet *pcpps) :
  50. CDialog(pcpps -> Instance(), AdvancedPage, pcpps -> Window()),
  51. m_cppsBoss(*pcpps){ }
  52. // Class destructor
  53. CAdvancedPage::~CAdvancedPage() {}
  54. // Update private function- fill the list box, and set all the buttons
  55. // properly.
  56. void CAdvancedPage::Update() {
  57. // Add the associations to the list
  58. SendDlgItemMessage(m_hwnd, DeviceListControl, LB_RESETCONTENT, 0, 0);
  59. for (unsigned u = m_cppsBoss.AssociationCount(); u--; ) {
  60. int iItem = SendDlgItemMessage(m_hwnd, DeviceListControl, LB_ADDSTRING,
  61. 0, (LPARAM) m_cppsBoss.DisplayName(u));
  62. SendDlgItemMessage(m_hwnd, DeviceListControl, LB_SETITEMDATA, iItem,
  63. (LPARAM) m_cppsBoss.Association(u));
  64. }
  65. // If there are no associations, disable the Remove Devices button
  66. EnableWindow(GetDlgItem(m_hwnd, RemoveDeviceButton),
  67. m_cppsBoss.Profile().AssociationCount());
  68. // If there are no devices, or all are associated, disable the Add
  69. // Devices button.
  70. EnableWindow(GetDlgItem(m_hwnd, AddDeviceButton),
  71. m_cppsBoss.Profile().DeviceCount() &&
  72. m_cppsBoss.Profile().DeviceCount() > m_cppsBoss.AssociationCount());
  73. }
  74. // OnInit function- this initializes the property page
  75. BOOL CAdvancedPage::OnInit() {
  76. SetDlgItemText(m_hwnd, ProfileNameControl, m_cppsBoss.Profile().GetName());
  77. // Add the associations to the list, etc.
  78. Update();
  79. return TRUE;
  80. }
  81. // OnCommand override- handles control notifications
  82. BOOL CAdvancedPage::OnCommand(WORD wNotifyCode, WORD wid, HWND hwndCtl) {
  83. switch (wid) {
  84. case AddDeviceButton:
  85. if (wNotifyCode == BN_CLICKED) {
  86. CAddDeviceDialog cadd(m_cppsBoss, m_hwnd);
  87. Update();
  88. return TRUE;
  89. }
  90. break;
  91. case RemoveDeviceButton:
  92. if (wNotifyCode == BN_CLICKED) {
  93. int i = SendDlgItemMessage(m_hwnd, DeviceListControl,
  94. LB_GETCURSEL, 0, 0);
  95. if (i == -1)
  96. return TRUE;
  97. unsigned uItem = SendDlgItemMessage(m_hwnd, DeviceListControl,
  98. LB_GETITEMDATA, i, 0);
  99. m_cppsBoss.Dissociate(uItem);
  100. Update();
  101. return TRUE;
  102. }
  103. break;
  104. case DeviceListControl:
  105. switch (wNotifyCode) {
  106. case LBN_SELCHANGE:
  107. EnableWindow(GetDlgItem(m_hwnd, RemoveDeviceButton),
  108. -1 != SendMessage(hwndCtl, LB_GETCURSEL, 0, 0));
  109. return TRUE;
  110. }
  111. break;
  112. }
  113. return FALSE;
  114. }
  115. // CAddDeviceDialog class constructor
  116. CAddDeviceDialog::CAddDeviceDialog(CProfilePropertySheet& cpps,
  117. HWND hwndParent) :
  118. CDialog(cpps.Instance(), AddDeviceDialog, hwndParent), m_cppsBoss(cpps) {
  119. DoModal();
  120. }
  121. // Dialog Initialization routine
  122. BOOL CAddDeviceDialog::OnInit() {
  123. CProfile& cpThis = m_cppsBoss.Profile();
  124. m_hwndList = GetDlgItem(m_hwnd, DeviceListControl);
  125. m_hwndButton = GetDlgItem(m_hwnd, AddDeviceButton);
  126. // This must not list associated (tentatively) devices, per the spec
  127. for (unsigned uDevice = 0; uDevice < cpThis.DeviceCount(); uDevice++) {
  128. for (unsigned u = 0; u < m_cppsBoss.AssociationCount(); u++)
  129. if (uDevice == m_cppsBoss.Association(u))
  130. break;
  131. if (u < m_cppsBoss.AssociationCount())
  132. continue; // Don't insert this one...
  133. int idItem = SendMessage(m_hwndList, LB_ADDSTRING, 0,
  134. (LPARAM) cpThis.DisplayName(uDevice));
  135. SendMessage(m_hwndList, LB_SETITEMDATA, idItem, (LPARAM) uDevice);
  136. }
  137. if (SendMessage(m_hwndList, LB_GETCOUNT, 0, 0))
  138. SendMessage(m_hwndList, LB_SETCURSEL, 0, 0);
  139. EnableWindow(m_hwndButton, -1 !=
  140. SendMessage(m_hwndList, LB_GETCURSEL, 0, 0));
  141. return TRUE;
  142. }
  143. // Dialog notification handler
  144. BOOL CAddDeviceDialog::OnCommand(WORD wNotification, WORD wid,
  145. HWND hwndControl){
  146. switch (wNotification) {
  147. case LBN_SELCHANGE:
  148. EnableWindow(m_hwndButton, -1 !=
  149. SendMessage(m_hwndList, LB_GETCURSEL, 0, 0));
  150. return TRUE;
  151. case BN_CLICKED:
  152. if (wid == AddDeviceButton) {
  153. int i = SendMessage(m_hwndList, LB_GETCURSEL, 0, 0);
  154. if (i == -1)
  155. return TRUE;
  156. unsigned uItem = (unsigned) SendMessage(m_hwndList,
  157. LB_GETITEMDATA, i, 0);
  158. m_cppsBoss.Associate(uItem);
  159. }
  160. break;
  161. case LBN_DBLCLK:
  162. return OnCommand(BN_CLICKED, AddDeviceButton, m_hwndButton);
  163. }
  164. return CDialog::OnCommand(wNotification, wid, hwndControl);
  165. }