Source code of Windows XP (NT5)
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.

214 lines
6.6 KiB

  1. // Copyright (C) Microsoft Corporation 1993-1997, All Rights reserved.
  2. #include "header.h"
  3. #include "cprop.h"
  4. // enumerated type so debugger can show us what codes are being sent
  5. typedef enum {
  6. tPSN_SETACTIVE = (PSN_FIRST-0),
  7. tPSN_KILLACTIVE = (PSN_FIRST-1),
  8. tPSN_APPLY = (PSN_FIRST-2),
  9. tPSN_RESET = (PSN_FIRST-3),
  10. tPSN_HELP = (PSN_FIRST-5),
  11. tPSN_WIZBACK = (PSN_FIRST-6),
  12. tPSN_WIZNEXT = (PSN_FIRST-7),
  13. tPSN_WIZFINISH = (PSN_FIRST-8),
  14. tPSN_QUERYCANCEL = (PSN_FIRST-9),
  15. } TYPE_PSN;
  16. int CALLBACK CPropSheetProc(HWND hdlg, UINT msg, LPARAM lParam);
  17. BOOL CALLBACK CPropPageProc(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam)
  18. {
  19. CPropPage* pThis = (CPropPage*) GetWindowLongPtr(hdlg, GWLP_USERDATA);;
  20. TYPE_PSN code;
  21. BOOL fResult;
  22. switch (msg) {
  23. case WM_INITDIALOG:
  24. pThis = (CPropPage*) ((LPPROPSHEETPAGE) lParam)->lParam;
  25. CDlgProc(hdlg, msg, wParam, (LPARAM) pThis);
  26. //BUG 2035: Return TRUE to tell windows to set the keyboard focus.
  27. // m_fFocusChanged is FALSE if the derived class hasn't changed it.
  28. return !pThis->m_fFocusChanged;
  29. case WM_COMMAND:
  30. if (!pThis || pThis->m_fShuttingDown)
  31. return FALSE; // pThis == NULL if a spin control is being initialized
  32. switch (HIWORD(wParam)) {
  33. case BN_CLICKED:
  34. pThis->OnButton(LOWORD(wParam));
  35. break;
  36. case LBN_SELCHANGE: // same value as CBN_SELCHANGE
  37. pThis->OnSelChange(LOWORD(wParam));
  38. break;
  39. case LBN_DBLCLK: // same value as CBN_DBLCLK
  40. pThis->OnDoubleClick(LOWORD(wParam));
  41. break;
  42. case EN_CHANGE:
  43. pThis->OnEditChange(LOWORD(wParam));
  44. break;
  45. }
  46. // If m_pmsglist is set, OnCommand will call OnMsg
  47. if (!pThis->OnCommand(wParam, lParam))
  48. return FALSE;
  49. break;
  50. case WM_NOTIFY:
  51. code = (TYPE_PSN) ((NMHDR*) lParam) ->code;
  52. switch(code) {
  53. case tPSN_APPLY: // OK or Apply Now
  54. pThis->m_fInitializing = FALSE;
  55. if (pThis->m_pBeginOrEnd)
  56. pThis->m_pBeginOrEnd(pThis);
  57. else
  58. pThis->OnBeginOrEnd();
  59. return FALSE;
  60. case tPSN_WIZNEXT:
  61. case tPSN_WIZFINISH:
  62. pThis->m_fInitializing = FALSE;
  63. fResult = -1;
  64. if (pThis->m_pBeginOrEnd)
  65. fResult = pThis->m_pBeginOrEnd(pThis);
  66. else
  67. fResult = pThis->OnBeginOrEnd();
  68. if (!fResult) {
  69. pThis->SetResult(-1);
  70. return TRUE;
  71. }
  72. else
  73. return pThis->OnNotify((UINT) code);
  74. break;
  75. default:
  76. return pThis->OnNotify((UINT) code);
  77. }
  78. break;
  79. case WM_HELP:
  80. pThis->OnHelp((HWND) ((LPHELPINFO) lParam)->hItemHandle);
  81. break;
  82. case WM_CONTEXTMENU:
  83. pThis->OnContextMenu((HWND) wParam);
  84. break;
  85. case WM_DRAWITEM:
  86. if (!pThis)
  87. return FALSE;
  88. if (pThis->m_pCheckBox &&
  89. GetDlgItem(hdlg, (int)wParam) == pThis->m_pCheckBox->m_hWnd) {
  90. ASSERT(IsValidWindow(pThis->m_pCheckBox->m_hWnd));
  91. pThis->m_pCheckBox->DrawItem((DRAWITEMSTRUCT*) lParam);
  92. return TRUE;
  93. }
  94. else
  95. return pThis->OnDlgMsg(msg, wParam, lParam) != NULL;
  96. case WM_VKEYTOITEM:
  97. if (pThis && pThis->m_pCheckBox && (HWND) lParam == pThis->m_pCheckBox->m_hWnd) {
  98. if (LOWORD(wParam) == VK_SPACE) {
  99. int cursel = (int)pThis->m_pCheckBox->GetCurSel();
  100. if (cursel != LB_ERR)
  101. pThis->m_pCheckBox->ToggleItem(cursel);
  102. }
  103. return -1; // always perform default action
  104. }
  105. else
  106. return pThis->OnDlgMsg(msg, wParam, lParam)!=NULL;
  107. default:
  108. if (pThis)
  109. return pThis->OnDlgMsg(msg, wParam, lParam)!=NULL;
  110. else
  111. return FALSE;
  112. }
  113. return FALSE;
  114. }
  115. CPropSheet::CPropSheet(PCSTR pszTitle, DWORD dwFlags, HWND hwndParent)
  116. {
  117. ZERO_INIT_CLASS(CPropSheet);
  118. m_psh.dwSize = sizeof(m_psh);
  119. m_psh.dwFlags = dwFlags;
  120. m_psh.hwndParent = hwndParent;
  121. m_psh.hInstance = _Module.GetResourceInstance();
  122. m_psh.pszCaption = pszTitle;
  123. m_psh.phpage = (HPROPSHEETPAGE*)
  124. lcCalloc(sizeof(HPROPSHEETPAGE) * MAXPROPPAGES);
  125. m_fNoCsHelp = FALSE;
  126. }
  127. CPropPage::CPropPage(int idTemplate) : CDlg((HWND) NULL, idTemplate)
  128. {
  129. ClearMemory(&m_psp, sizeof(m_psp));
  130. m_psp.dwSize = sizeof(m_psp);
  131. m_psp.dwFlags = PSP_DEFAULT;
  132. m_psp.hInstance = _Module.GetResourceInstance(); // means the dll can't create a property sheet [REVIEW: What does this comment meand 3/98 dalero]
  133. m_psp.lParam = (LPARAM) this;
  134. m_idTemplate = idTemplate;
  135. if (idTemplate) {
  136. m_psp.pszTemplate = MAKEINTRESOURCE(idTemplate);
  137. ASSERT(m_psp.pszTemplate);
  138. }
  139. m_psp.pfnDlgProc = (DLGPROC) CPropPageProc;
  140. m_fCenterWindow = FALSE; // Don't automatically center the window
  141. }
  142. CPropSheet::~CPropSheet()
  143. {
  144. lcFree(m_psh.phpage);
  145. }
  146. void CPropSheet::AddPage(CPropPage* pPage)
  147. {
  148. HPROPSHEETPAGE hprop = CreatePropertySheetPage(&pPage->m_psp);
  149. ASSERT_COMMENT(hprop, "Failed to create property sheet page.");
  150. if (hprop)
  151. m_psh.phpage[m_psh.nPages++] = hprop;
  152. }
  153. int CPropSheet::DoModal(void)
  154. {
  155. if (m_fNoCsHelp) {
  156. m_psh.dwFlags |= PSH_USECALLBACK;
  157. m_psh.pfnCallback = CPropSheetProc;
  158. }
  159. int err = (int)PropertySheet(&m_psh);
  160. ASSERT(err >= 0);
  161. return err;
  162. }
  163. /***************************************************************************
  164. FUNCTION: CPropSheetProc
  165. PURPOSE: Called to remove context-sensitive help
  166. ***************************************************************************/
  167. int CALLBACK CPropSheetProc(HWND hdlg, UINT msg, LPARAM lParam)
  168. {
  169. if (msg == PSCB_INITIALIZED) {
  170. SetWindowLong(hdlg, GWL_EXSTYLE,
  171. (GetWindowLong(hdlg, GWL_EXSTYLE) & ~WS_EX_CONTEXTHELP));
  172. }
  173. return 0;
  174. }