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.

277 lines
7.2 KiB

  1. //Copyright (c) 1997-2000 Microsoft Corporation
  2. #ifndef __WIZARD_PAGE_BASECLASS_H
  3. #define __WIZARD_PAGE_BASECLASS_H
  4. //
  5. // Special "Wizard Page Messages"
  6. //
  7. #include "AccWiz.h" // JMC: TODO: Maybe move this somewhere else
  8. class CWizardPageOrder
  9. {
  10. public:
  11. CWizardPageOrder()
  12. {
  13. m_nCount = 0;
  14. for(int i=0;i<ARRAYSIZE(m_rgdwPageIds);i++)
  15. m_rgdwPageIds[i] = 0;
  16. }
  17. BOOL AddPages(DWORD nInsertAfter, DWORD *rgdwIds, int nCount)
  18. {
  19. // First remove the pages if they are already there
  20. RemovePages(rgdwIds, nCount);
  21. int nStart = m_nCount - 1; // This will add to the end of the array
  22. if(0xFFFFFFFF != nInsertAfter)
  23. {
  24. for(nStart = 0;nStart < m_nCount;nStart++)
  25. if(m_rgdwPageIds[nStart] == nInsertAfter) break;
  26. if(nStart >= m_nCount)
  27. {
  28. _ASSERTE(FALSE); // The specified insert after was not in the array
  29. return FALSE;
  30. }
  31. }
  32. // Check to see if we have enough space.
  33. if(nCount + m_nCount > ARRAYSIZE(m_rgdwPageIds))
  34. {
  35. _ASSERTE(FALSE); // We don't have space
  36. return FALSE;
  37. }
  38. // Move current allocation upwards
  39. for(int i=m_nCount-1;i>nStart;i--)
  40. m_rgdwPageIds[i + nCount] = m_rgdwPageIds[i];
  41. // Insert new values
  42. for(i = 0;i<nCount;i++)
  43. m_rgdwPageIds[nStart + i + 1] = rgdwIds[i];
  44. // Set new value for m_nCount
  45. m_nCount += nCount;
  46. return TRUE;
  47. }
  48. BOOL RemovePages(DWORD *rgdwIds, int nCount)
  49. {
  50. // NOTE: This will scan the array and find the max and min locations
  51. // of all the elements in rgdwIds. It then removes everything from min to max.
  52. // This is needed in case a sub page added more sub pages.
  53. int nMin = m_nCount + 1;
  54. int nMax = 0;
  55. for(int i=0;i<m_nCount;i++)
  56. {
  57. for(int j=0;j<nCount;j++)
  58. {
  59. if(m_rgdwPageIds[i] == rgdwIds[j])
  60. {
  61. nMin = min(i, nMin);
  62. nMax = max(i, nMax);
  63. }
  64. }
  65. }
  66. if(nMax < nMin)
  67. {
  68. // _ASSERTE(FALSE); // we could not find the range
  69. return FALSE;
  70. }
  71. // Move elements down
  72. int nCountElementsToRemove = nMax - nMin + 1;
  73. for(i=0;i<m_nCount - (nMax + 1);i++)
  74. m_rgdwPageIds[nMin + i] = m_rgdwPageIds[nMin + i + nCountElementsToRemove];
  75. // Figure out new m_nCount;
  76. m_nCount -= nCountElementsToRemove;
  77. return TRUE;
  78. }
  79. DWORD GetNextPage(DWORD dwPageId)
  80. {
  81. DWORD dwNextPage = 0;
  82. // Find the specified page
  83. for(int i=0;i<m_nCount;i++)
  84. if(m_rgdwPageIds[i] == dwPageId) break;
  85. if(i>=m_nCount)
  86. {
  87. _ASSERTE(FALSE); // We could not find the current page
  88. return 0;
  89. }
  90. // If we are not on the last page, return the 'next' page
  91. if(i < (m_nCount-1))
  92. dwNextPage = m_rgdwPageIds[i+1];
  93. return dwNextPage;
  94. }
  95. DWORD GetPrevPage(DWORD dwPageId)
  96. {
  97. DWORD dwPrevPage = 0;
  98. // Find the specified page
  99. for(int i=0;i<m_nCount;i++)
  100. if(m_rgdwPageIds[i] == dwPageId) break;
  101. if(i>=m_nCount)
  102. {
  103. _ASSERTE(FALSE); // We could not find the current page
  104. return 0;
  105. }
  106. // If we are not on the first page, return the 'prev' page
  107. if(i > 0)
  108. dwPrevPage = m_rgdwPageIds[i - 1];
  109. return dwPrevPage;
  110. }
  111. DWORD GetFirstPage()
  112. {
  113. _ASSERTE(m_nCount); // only call if we have values in the class
  114. return m_rgdwPageIds[0];
  115. }
  116. BOOL GrowArray(int nNewMax)
  117. {
  118. _ASSERTE(FALSE); // Not yet implemented
  119. return FALSE;
  120. }
  121. protected:
  122. int m_nCount;
  123. DWORD m_rgdwPageIds[100]; // JMC: NOTE: We hard code a max of 100 pages that this
  124. // object can support. 100 is reasonable, since wizards
  125. // cannot currently support more than 100 pages.
  126. };
  127. class WizardPage
  128. {
  129. public:
  130. WizardPage(LPPROPSHEETPAGE ppsp, int nIdTitle, int nIdSubTitle);
  131. virtual ~WizardPage(VOID);
  132. //
  133. // Object is to apply settings to the system so that they take effect.
  134. //
  135. virtual LRESULT ApplySettings(VOID)
  136. { return 0; }
  137. //
  138. // Object reports if user has changed something in the wizard page.
  139. //
  140. virtual BOOL Changed(VOID)
  141. { return FALSE; }
  142. //
  143. // Object is to restore the original settings in effect when the page
  144. // was first opened.
  145. // Don't appy these to the system. Object will receive an
  146. // ApplySettings notification when this is required.
  147. //
  148. virtual VOID RestoreOriginalSettings(VOID)
  149. { /* By default, nothing happens */ }
  150. //
  151. // Object is to restore the settings most previously applied.
  152. // Don't appy these to the system. Object will receive an
  153. // ApplySettings notification when this is required.
  154. //
  155. virtual VOID RestorePreviousSettings(VOID)
  156. { /* By default, nothing happens */ }
  157. // This static member contains the order for all wizard pages in the app
  158. static CWizardPageOrder sm_WizPageOrder;
  159. protected:
  160. HWND m_hwnd; // Dialog's hwnd.
  161. DWORD m_dwPageId;
  162. virtual BOOL AdjustWizPageOrder()
  163. {
  164. // Default does nothing
  165. return TRUE;
  166. }
  167. //
  168. // Derived classes override these to respond to page create/release
  169. // notifications.
  170. //
  171. virtual UINT OnPropSheetPageCreate(HWND hwnd, LPPROPSHEETPAGE ppsp)
  172. { return 1; }
  173. virtual UINT OnPropSheetPageRelease(HWND hwnd, LPPROPSHEETPAGE ppsp)
  174. { return 1; }
  175. //
  176. // Method for performing operations common to all wizard pages in response
  177. // to given messages. This is the function given to the PROPSHEETPAGE struct.
  178. //
  179. static INT_PTR DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  180. protected:
  181. //
  182. // Prevent copying.
  183. //
  184. WizardPage(const WizardPage& rhs);
  185. WizardPage& operator = (const WizardPage& rhs);
  186. static UINT PropSheetPageCallback(HWND hwnd, UINT uMsg, LPPROPSHEETPAGE ppsp);
  187. virtual LRESULT HandleMsg(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  188. { return 0; }
  189. virtual LRESULT OnInitDialog(HWND hwnd, WPARAM wParam, LPARAM lParam)
  190. { return 1; }
  191. //
  192. // Property sheet notifications.
  193. //
  194. virtual LRESULT OnPSN_Apply(HWND hwnd, INT idCtl, LPPSHNOTIFY pnmh)
  195. { return 0; }
  196. virtual LRESULT OnPSN_Help(HWND hwnd, INT idCtl, LPPSHNOTIFY pnmh)
  197. { return 0; }
  198. virtual LRESULT OnPSN_KillActive(HWND hwnd, INT idCtl, LPPSHNOTIFY pnmh)
  199. { return 0; }
  200. virtual LRESULT OnPSN_QueryCancel(HWND hwnd, INT idCtl, LPPSHNOTIFY pnmh);
  201. virtual LRESULT OnPSN_Reset(HWND hwnd, INT idCtl, LPPSHNOTIFY pnmh)
  202. { return 0; }
  203. virtual LRESULT OnPSN_SetActive(HWND hwnd, INT idCtl, LPPSHNOTIFY pnmh);
  204. virtual LRESULT OnPSN_WizBack(HWND hwnd, INT idCtl, LPPSHNOTIFY pnmh)
  205. {
  206. AdjustWizPageOrder();
  207. SetWindowLongPtr(hwnd, DWLP_MSGRESULT,
  208. sm_WizPageOrder.GetPrevPage(m_dwPageId));
  209. return TRUE;
  210. }
  211. virtual LRESULT OnPSN_WizNext(HWND hwnd, INT idCtl, LPPSHNOTIFY pnmh)
  212. {
  213. AdjustWizPageOrder();
  214. SetWindowLongPtr(hwnd, DWLP_MSGRESULT,
  215. sm_WizPageOrder.GetNextPage(m_dwPageId));
  216. return TRUE;
  217. }
  218. virtual LRESULT OnPSN_WizFinish(HWND hwnd, INT idCtl, LPPSHNOTIFY pnmh)
  219. { return 0; }
  220. virtual LRESULT OnCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
  221. { return 0; }
  222. virtual LRESULT OnDrawItem(HWND hwnd, WPARAM wParam, LPARAM lParam)
  223. { return 0; }
  224. virtual LRESULT OnTimer(HWND hwnd, WPARAM wParam, LPARAM lParam)
  225. { return 0; }
  226. virtual BOOL OnMsgNotify(HWND hwnd, int idCtrl, LPNMHDR pnmh)
  227. { return 0; }
  228. LRESULT OnPSM_QuerySiblings(HWND hwnd, WPARAM wParam, LPARAM lParam);
  229. LRESULT OnNotify(HWND hwnd, WPARAM wParam, LPARAM lParam);
  230. };
  231. #endif // __WIZARD_PAGE_H