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.

162 lines
4.2 KiB

  1. /****************************************************************************
  2. Copyright (c) Microsoft Corporation 1998
  3. All rights reserved
  4. File: SERVERDLG.CPP
  5. ***************************************************************************/
  6. #include "pch.h"
  7. #include <remboot.h>
  8. #include "callback.h"
  9. #include "utils.h"
  10. DEFINE_MODULE( "RIPREP" )
  11. WNDPROC g_pOldEditWndProc;
  12. //
  13. // VerifySIFField( )
  14. //
  15. // Make sure that the directory name entered conforms to the
  16. // restrictions that OSChooser has.
  17. //
  18. // Returns: S_OK if it does
  19. // E_FAIL if it does not
  20. //
  21. HRESULT
  22. VerifySIFField(
  23. LPWSTR pszField
  24. )
  25. {
  26. HRESULT hr = S_OK;
  27. TraceFunc( "VerifySIFField()\n" );
  28. while ( *pszField >= 32 && *pszField <= 127 )
  29. {
  30. pszField++;
  31. }
  32. if ( *pszField != L'\0' )
  33. {
  34. hr = E_FAIL;
  35. }
  36. HRETURN(hr);
  37. }
  38. //
  39. // SIFDlgCheckNextButtonActivation( )
  40. //
  41. VOID
  42. SIFDlgCheckNextButtonActivation(
  43. HWND hDlg )
  44. {
  45. TraceFunc( "SIFDlgCheckNextButtonActivation( )\n" );
  46. GetDlgItemText( hDlg, IDC_E_DESCRIPTION, g_Description, ARRAYSIZE(g_Description));
  47. PropSheet_SetWizButtons( GetParent( hDlg ), PSWIZB_BACK | (wcslen(g_Description) ? PSWIZB_NEXT : 0 ) );
  48. TraceFuncExit( );
  49. }
  50. //
  51. // HelpTextEditWndProc( )
  52. //
  53. LRESULT CALLBACK
  54. HelpTextEditWndProc(
  55. HWND hWnd,
  56. UINT uMsg,
  57. WPARAM wParam,
  58. LPARAM lParam )
  59. {
  60. switch ( uMsg )
  61. {
  62. case WM_KEYDOWN:
  63. // fake button presses
  64. if ( LOWORD( wParam ) == VK_RETURN ) {
  65. PropSheet_PressButton( GetParent( GetParent( hWnd ) ), PSBTN_NEXT );
  66. return FALSE;
  67. } else if ( LOWORD( wParam ) == VK_ESCAPE ) {
  68. PropSheet_PressButton( GetParent( GetParent( hWnd ) ), PSBTN_CANCEL );
  69. return FALSE;
  70. }
  71. break;
  72. }
  73. return CallWindowProc(g_pOldEditWndProc, hWnd, uMsg, wParam, lParam);
  74. }
  75. //
  76. // SIFDlgProc()
  77. //
  78. INT_PTR CALLBACK
  79. SIFDlgProc(
  80. HWND hDlg,
  81. UINT uMsg,
  82. WPARAM wParam,
  83. LPARAM lParam )
  84. {
  85. switch (uMsg)
  86. {
  87. default:
  88. return FALSE;
  89. case WM_INITDIALOG:
  90. Edit_LimitText( GetDlgItem( hDlg, IDC_E_DESCRIPTION ), ARRAYSIZE(g_Description) - 1 );
  91. Edit_LimitText( GetDlgItem( hDlg, IDC_E_HELPTEXT ), ARRAYSIZE(g_HelpText) - 1 );
  92. g_pOldEditWndProc = (WNDPROC) SetWindowLongPtr( GetDlgItem( hDlg, IDC_E_HELPTEXT), GWLP_WNDPROC, (LONG_PTR)&HelpTextEditWndProc);
  93. SetWindowLongPtr( GetDlgItem( hDlg, IDC_E_HELPTEXT), GWLP_WNDPROC, (LONG_PTR)&HelpTextEditWndProc);
  94. break;
  95. case WM_COMMAND:
  96. switch ( LOWORD( wParam ) )
  97. {
  98. case IDC_E_DESCRIPTION:
  99. if ( HIWORD( wParam ) == EN_CHANGE )
  100. {
  101. SIFDlgCheckNextButtonActivation( hDlg );
  102. }
  103. break;
  104. }
  105. break;
  106. case WM_NOTIFY:
  107. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, FALSE );
  108. LPNMHDR lpnmhdr = (LPNMHDR) lParam;
  109. switch ( lpnmhdr->code )
  110. {
  111. case PSN_WIZNEXT:
  112. GetDlgItemText( hDlg, IDC_E_DESCRIPTION, g_Description, ARRAYSIZE(g_Description) );
  113. Assert( wcslen( g_Description ) );
  114. GetDlgItemText( hDlg, IDC_E_HELPTEXT, g_HelpText, ARRAYSIZE(g_HelpText) );
  115. if ( FAILED( VerifySIFField( g_Description ) ) )
  116. {
  117. MessageBoxFromStrings( hDlg, IDS_OSCHOOSER_RESTRICTION_FIELDS_TITLE, IDS_OSCHOOSER_RESTRICTION_FIELDS_TEXT, MB_OK );
  118. SetFocus( GetDlgItem( hDlg, IDC_E_DESCRIPTION ) );
  119. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 ); // don't go on
  120. break;
  121. }
  122. if ( FAILED( VerifySIFField( g_HelpText ) ) )
  123. {
  124. MessageBoxFromStrings( hDlg, IDS_OSCHOOSER_RESTRICTION_FIELDS_TITLE, IDS_OSCHOOSER_RESTRICTION_FIELDS_TEXT, MB_OK );
  125. SetFocus( GetDlgItem( hDlg, IDC_E_HELPTEXT ) );
  126. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 ); // don't go on
  127. break;
  128. }
  129. break;
  130. case PSN_QUERYCANCEL:
  131. return VerifyCancel( hDlg );
  132. case PSN_SETACTIVE:
  133. SIFDlgCheckNextButtonActivation( hDlg );
  134. ClearMessageQueue( );
  135. break;
  136. }
  137. break;
  138. }
  139. return TRUE;
  140. }