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.

332 lines
8.7 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. // All rights reserved.
  5. //
  6. // File Name:
  7. // newedit.c
  8. //
  9. // Description:
  10. // This file has the dialog proc for the New Or Edit Script page.
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "pch.h"
  14. #include "resource.h"
  15. //----------------------------------------------------------------------------
  16. //
  17. // Function: GreyUnGreyNewEdit
  18. //
  19. // Purpose: Greys/ungreys controls on this page.
  20. //
  21. //----------------------------------------------------------------------------
  22. VOID GreyUnGreyNewEdit(HWND hwnd)
  23. {
  24. BOOL bUnGrey = IsDlgButtonChecked(hwnd, IDC_EDITSCRIPT);
  25. EnableWindow(GetDlgItem(hwnd, IDT_SCRIPTNAME), bUnGrey);
  26. EnableWindow(GetDlgItem(hwnd, IDC_BROWSE), bUnGrey);
  27. EnableWindow(GetDlgItem(hwnd, IDC_GREYTEXT), bUnGrey);
  28. }
  29. //----------------------------------------------------------------------------
  30. //
  31. // Function: OnEditOrNewInitDialog
  32. //
  33. // Purpose:
  34. //
  35. // Arguments: IN HWND hwnd - handle to the dialog box
  36. //
  37. // Returns: VOID
  38. //
  39. //----------------------------------------------------------------------------
  40. VOID
  41. OnEditOrNewInitDialog( IN HWND hwnd ) {
  42. //
  43. // If they specifed an answer file on the command line, then pre-fill
  44. // this page with it
  45. //
  46. if( lstrcmp( FixedGlobals.ScriptName, _T("") ) != 0 ) {
  47. FixedGlobals.iLoadType = LOAD_FROM_ANSWER_FILE;
  48. }
  49. }
  50. //----------------------------------------------------------------------------
  51. //
  52. // Function: OnSetActiveNewOrEdit
  53. //
  54. // Purpose: Called at SETACTIVE time. Fill in the controls.
  55. //
  56. //----------------------------------------------------------------------------
  57. VOID OnSetActiveNewOrEdit(HWND hwnd)
  58. {
  59. int nButtonId = IDC_NEWSCRIPT;
  60. //
  61. // Map the current load type to a radio button
  62. //
  63. switch ( FixedGlobals.iLoadType ) {
  64. case LOAD_UNDEFINED:
  65. case LOAD_NEWSCRIPT_DEFAULTS:
  66. nButtonId = IDC_NEWSCRIPT;
  67. break;
  68. case LOAD_FROM_ANSWER_FILE:
  69. nButtonId = IDC_EDITSCRIPT;
  70. SetWindowText( GetDlgItem( hwnd, IDT_SCRIPTNAME ),
  71. FixedGlobals.ScriptName );
  72. break;
  73. default:
  74. AssertMsg(FALSE, "Bad case OnSetActiveNewEdit");
  75. break;
  76. }
  77. CheckRadioButton(hwnd,
  78. IDC_NEWSCRIPT,
  79. IDC_EDITSCRIPT,
  80. nButtonId);
  81. GreyUnGreyNewEdit(hwnd);
  82. PropSheet_SetWizButtons(GetParent(hwnd), PSWIZB_BACK | PSWIZB_NEXT);
  83. }
  84. //----------------------------------------------------------------------------
  85. //
  86. // Function: OnRadioButtonNewOrEdit
  87. //
  88. // Purpose: Called when a radio button is pushed. Update
  89. // FixedGlobals.bEditScript & Grey/ungrey controls.
  90. //
  91. //----------------------------------------------------------------------------
  92. VOID OnRadioButtonNewOrEdit(HWND hwnd, int nButtonId)
  93. {
  94. CheckRadioButton(hwnd,
  95. IDC_NEWSCRIPT,
  96. IDC_EDITSCRIPT,
  97. nButtonId);
  98. GreyUnGreyNewEdit(hwnd);
  99. }
  100. //----------------------------------------------------------------------------
  101. //
  102. // Function: OnBrowseNewOrEdit
  103. //
  104. // Purpose: Called when the browse button is pushed.
  105. //
  106. //----------------------------------------------------------------------------
  107. VOID OnBrowseNewOrEdit(HWND hwnd)
  108. {
  109. GetAnswerFileName(hwnd, FixedGlobals.ScriptName, FALSE);
  110. SendDlgItemMessage(hwnd,
  111. IDT_SCRIPTNAME,
  112. WM_SETTEXT,
  113. (WPARAM) MAX_PATH,
  114. (LPARAM) FixedGlobals.ScriptName);
  115. }
  116. //----------------------------------------------------------------------------
  117. //
  118. // Function: OnWizNextNewOrEdit
  119. //
  120. // Purpose: Called when the Next button is pushed. Retrieve the settings
  121. // of the controls and validate.
  122. //
  123. //----------------------------------------------------------------------------
  124. BOOL OnWizNextNewOrEdit(HWND hwnd)
  125. {
  126. BOOL bNewScript;
  127. BOOL bReturn = TRUE;
  128. LOAD_TYPES NewLoadType;
  129. //
  130. // Figure out where the user wants to load answers from
  131. //
  132. if ( IsDlgButtonChecked(hwnd, IDC_NEWSCRIPT) )
  133. {
  134. NewLoadType = LOAD_NEWSCRIPT_DEFAULTS;
  135. bNewScript = TRUE;
  136. }
  137. else
  138. {
  139. NewLoadType = LOAD_FROM_ANSWER_FILE;
  140. bNewScript = FALSE;
  141. }
  142. //
  143. // If we're loading from an answer file, retrieve the filename.
  144. //
  145. if ( NewLoadType == LOAD_FROM_ANSWER_FILE ) {
  146. SendDlgItemMessage(hwnd,
  147. IDT_SCRIPTNAME,
  148. WM_GETTEXT,
  149. (WPARAM) MAX_PATH,
  150. (LPARAM) FixedGlobals.ScriptName);
  151. MyGetFullPath(FixedGlobals.ScriptName);
  152. if ( FixedGlobals.ScriptName[0] == _T('\0') ) {
  153. ReportErrorId(hwnd, MSGTYPE_ERR, IDS_ERR_ENTER_FILENAME);
  154. bReturn = FALSE;
  155. }
  156. if( bReturn )
  157. {
  158. INT nStrLen;
  159. TCHAR *pFileExtension;
  160. lstrcpyn( FixedGlobals.UdfFileName, FixedGlobals.ScriptName, AS(FixedGlobals.UdfFileName) );
  161. nStrLen = lstrlen( FixedGlobals.UdfFileName );
  162. pFileExtension = FixedGlobals.UdfFileName + ( nStrLen - 3 );
  163. lstrcpyn( pFileExtension, _T("udf"), AS(FixedGlobals.UdfFileName)-nStrLen+3);
  164. }
  165. }
  166. //
  167. // Load the answers
  168. //
  169. if ( bReturn ) {
  170. if ( ! LoadAllAnswers(hwnd, NewLoadType) )
  171. {
  172. bReturn = FALSE;
  173. }
  174. }
  175. FixedGlobals.iLoadType = NewLoadType;
  176. WizGlobals.bNewScript = bNewScript;
  177. return ( bReturn );
  178. }
  179. //----------------------------------------------------------------------------
  180. //
  181. // Function: DlgEditOrNewPage
  182. //
  183. // Purpose: Dialog procedure for the edit or new script page.
  184. //
  185. //----------------------------------------------------------------------------
  186. INT_PTR CALLBACK DlgEditOrNewPage(
  187. IN HWND hwnd,
  188. IN UINT uMsg,
  189. IN WPARAM wParam,
  190. IN LPARAM lParam)
  191. {
  192. BOOL bStatus = TRUE;
  193. switch(uMsg) {
  194. case WM_INITDIALOG:
  195. OnEditOrNewInitDialog( hwnd );
  196. break;
  197. case WM_COMMAND:
  198. {
  199. int nButtonId=LOWORD(wParam);
  200. switch ( nButtonId ) {
  201. case IDC_NEWSCRIPT:
  202. case IDC_EDITSCRIPT:
  203. if ( HIWORD(wParam) == BN_CLICKED )
  204. OnRadioButtonNewOrEdit(hwnd, nButtonId);
  205. break;
  206. case IDC_BROWSE:
  207. if ( HIWORD(wParam) == BN_CLICKED )
  208. OnBrowseNewOrEdit(hwnd);
  209. break;
  210. default:
  211. bStatus = FALSE;
  212. break;
  213. }
  214. }
  215. break;
  216. case WM_NOTIFY:
  217. {
  218. LPNMHDR pnmh = (LPNMHDR)lParam;
  219. switch( pnmh->code ) {
  220. case PSN_QUERYCANCEL:
  221. WIZ_CANCEL(hwnd);
  222. break;
  223. case PSN_SETACTIVE:
  224. g_App.dwCurrentHelp = IDH_ANSW_FILE;
  225. // Set this flag so we don't get a prompt when user wants to cancel
  226. //
  227. SET_FLAG(OPK_EXIT, TRUE);
  228. SET_FLAG(OPK_CREATED, FALSE);
  229. WIZ_BUTTONS(hwnd, PSWIZB_BACK | PSWIZB_NEXT);
  230. OnSetActiveNewOrEdit(hwnd);
  231. break;
  232. case PSN_WIZBACK:
  233. bStatus = FALSE;
  234. break;
  235. case PSN_WIZNEXT:
  236. if ( !OnWizNextNewOrEdit(hwnd) )
  237. WIZ_FAIL(hwnd);
  238. else
  239. bStatus = FALSE;
  240. break;
  241. case PSN_HELP:
  242. WIZ_HELP();
  243. break;
  244. default:
  245. bStatus = FALSE;
  246. break;
  247. }
  248. }
  249. break;
  250. default:
  251. bStatus = FALSE;
  252. break;
  253. }
  254. return bStatus;
  255. }