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.

233 lines
6.9 KiB

  1. /******************************************************************************
  2. Source File: Profile Property Sheet.CPP
  3. This implements the code for the profile property sheet.
  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 "Resource.H"
  11. // Private ConstructAssociations function- this constructs the list of
  12. // tentative associations- this starts out as the true list from the profile
  13. // object, but reflects all adds and deletes made on the Advanced page.
  14. void CProfilePropertySheet::ConstructAssociations() {
  15. m_cuaAssociate.Empty(); // Clean it up!
  16. for (unsigned u = 0; u < m_cpTarget.AssociationCount(); u++) {
  17. for (unsigned uDelete = 0;
  18. uDelete < m_cuaDelete.Count();
  19. uDelete++)
  20. if (m_cuaDelete[uDelete] == m_cpTarget.Association(u))
  21. break;
  22. if (uDelete == m_cuaDelete.Count()) // Not yet deleted
  23. m_cuaAssociate.Add(m_cpTarget.Association(u));
  24. }
  25. // Now, add any added associations
  26. for (u = 0; u < m_cuaAdd.Count(); u++)
  27. m_cuaAssociate.Add(m_cuaAdd[u]);
  28. }
  29. // Class constructor- we use one dialog for the installed case, and another
  30. // for the uninstalled one. This traded code for resource size, since the
  31. // two forms are similar enough I can use the same code to handle both.
  32. // This is a tricky constructor- it actually presents the dialog when the
  33. // instance is constructed.
  34. CProfilePropertySheet::CProfilePropertySheet(HINSTANCE hiWhere,
  35. CProfile& cpTarget) :
  36. CDialog(hiWhere,
  37. cpTarget.IsInstalled() ? UninstallInterface : InstallInterface),
  38. m_cpTarget(cpTarget) {
  39. if (!cpTarget.IsValid()) {
  40. for (int i = 0; i < sizeof m_pcdPage / sizeof m_pcdPage[0]; i++)
  41. m_pcdPage[i] = NULL;
  42. CGlobals::Report(InvalidProfileString, m_hwndParent);
  43. return;
  44. }
  45. m_bDelete = FALSE;
  46. ConstructAssociations();
  47. DoModal();
  48. }
  49. // Class destructor- we have to get rid of the individual pages
  50. CProfilePropertySheet::~CProfilePropertySheet() {
  51. for (int i = 0; i < sizeof m_pcdPage / sizeof (m_pcdPage[0]); i++)
  52. if (m_pcdPage[i])
  53. delete m_pcdPage[i];
  54. }
  55. // Public method for noting tentative associations to be added
  56. void CProfilePropertySheet::Associate(unsigned uAdd) {
  57. // First, see if it's on the delete list. If it is, remove it from there
  58. // Otherwise, add us to the add list, if it's a new association.
  59. for (unsigned u = 0; u < m_cuaDelete.Count(); u++)
  60. if (uAdd == m_cuaDelete[u])
  61. break;
  62. if (u < m_cuaDelete.Count())
  63. m_cuaDelete.Remove(u);
  64. else {
  65. for (u = 0; u < m_cuaAssociate.Count(); u++)
  66. if (m_cuaAssociate[u] == uAdd)
  67. break;
  68. if (u == m_cuaAssociate.Count())
  69. m_cuaAdd.Add(uAdd);
  70. }
  71. ConstructAssociations();
  72. }
  73. // Public Method for removing tentative associations
  74. void CProfilePropertySheet::Dissociate(unsigned uRemove) {
  75. // First, see if it's on the add list. If it is, remove it from there
  76. // Otherwise, add us to the delete list.
  77. for (unsigned u = 0; u < m_cuaAdd.Count(); u++)
  78. if (uRemove == m_cuaAdd[u])
  79. break;
  80. if (u < m_cuaAdd.Count())
  81. m_cuaAdd.Remove(u);
  82. else
  83. m_cuaDelete.Add(uRemove);
  84. ConstructAssociations();
  85. }
  86. // Dialog Initialization override
  87. BOOL CProfilePropertySheet::OnInit() {
  88. CString csWork;
  89. TC_ITEM tciThis = {TCIF_TEXT, 0, 0, NULL, 0, -1, 0};
  90. // We'll begin by determining the bounding rectangle of the client
  91. // area of the tab control
  92. RECT rcWork;
  93. GetWindowRect(GetDlgItem(m_hwnd, TabControl), &m_rcTab);
  94. GetWindowRect(m_hwnd, &rcWork);
  95. OffsetRect(&m_rcTab, -rcWork.left, -rcWork.top);
  96. SendDlgItemMessage(m_hwnd, TabControl, TCM_ADJUSTRECT, FALSE,
  97. (LPARAM) &m_rcTab);
  98. // Then, we create the classes for the two descendants, and
  99. // initialize the first dialog.
  100. m_pcdPage[0] = new CInstallPage(this);
  101. m_pcdPage[1] = new CAdvancedPage(this);
  102. m_pcdPage[0] -> Create();
  103. m_pcdPage[0] -> Adjust(m_rcTab);
  104. // Then, initialize the tab control
  105. csWork.Load(m_cpTarget.IsInstalled() ?
  106. ShortUninstallString : ShortInstallString);
  107. tciThis.pszText = const_cast<LPTSTR>((LPCTSTR) csWork);
  108. SendDlgItemMessage(m_hwnd, TabControl, TCM_INSERTITEM, 0,
  109. (LPARAM) &tciThis);
  110. csWork.Load(AdvancedString);
  111. tciThis.pszText = const_cast<LPTSTR>((LPCTSTR) csWork);
  112. SendDlgItemMessage(m_hwnd, TabControl, TCM_INSERTITEM, 1,
  113. (LPARAM) &tciThis);
  114. // Finally, let's set the icons for this little monster...
  115. HICON hi = LoadIcon(m_hiWhere,
  116. MAKEINTRESOURCE(m_cpTarget.IsInstalled() ?
  117. DefaultIcon : UninstalledIcon));
  118. SendMessage(m_hwnd, WM_SETICON, ICON_BIG, (LPARAM) hi);
  119. return TRUE; // We've not set the focus anywhere
  120. }
  121. // Common control notification override
  122. BOOL CProfilePropertySheet::OnNotify(int idCtrl, LPNMHDR pnmh) {
  123. int iPage = !!SendMessage(pnmh -> hwndFrom, TCM_GETCURSEL, 0, 0);
  124. switch (pnmh -> code) {
  125. case TCN_SELCHANGING:
  126. m_pcdPage[iPage] -> Destroy();
  127. return FALSE; // Allow the selection to change.
  128. case TCN_SELCHANGE:
  129. // Create the appropriate dialog
  130. m_pcdPage[iPage] -> Create();
  131. m_pcdPage[iPage] -> Adjust(m_rcTab);
  132. return TRUE;
  133. }
  134. return TRUE; // Claim to have handled it (perhaps a bit bogus).
  135. }
  136. // Control Notification override
  137. BOOL CProfilePropertySheet::OnCommand(WORD wNotifyCode, WORD wid,
  138. HWND hwndControl) {
  139. switch (wid) {
  140. case IDOK:
  141. if (wNotifyCode == BN_CLICKED && !m_cpTarget.IsInstalled())
  142. m_cpTarget.Install();
  143. // Remove any associations we're removing
  144. while (m_cuaDelete.Count()) {
  145. m_cpTarget.Dissociate(m_cpTarget.Device(m_cuaDelete[0]));
  146. m_cuaDelete.Remove(0);
  147. }
  148. // Add any associations we're adding
  149. while (m_cuaAdd.Count()) {
  150. m_cpTarget.Associate(m_cpTarget.Device(m_cuaAdd[0]));
  151. m_cuaAdd.Remove(0);
  152. }
  153. break;
  154. case UninstallButton:
  155. if (wNotifyCode == BN_CLICKED)
  156. m_cpTarget.Uninstall(m_bDelete);
  157. break;
  158. }
  159. return CDialog::OnCommand(wNotifyCode, wid, hwndControl);
  160. }