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.

302 lines
8.7 KiB

  1. #include "stdafx.h"
  2. #include "WizardSheet.h"
  3. #include "CommandDlg.h"
  4. CPostProcessAdd::CPostProcessAdd( CWizardSheet* pTheSheet ) :
  5. m_pTheSheet( pTheSheet )
  6. {
  7. m_strTitle.LoadString( IDS_TITLE_POSTPROCESS );
  8. m_strSubTitle.LoadString( IDS_SUBTITLE_POSTPROCESS );
  9. SetHeaderTitle( m_strTitle );
  10. SetHeaderSubTitle( m_strSubTitle );
  11. }
  12. LRESULT CPostProcessAdd::OnAddFile( WORD wNotifyCode, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled )
  13. {
  14. CString strFilter;
  15. UIUtils::LoadOFNFilterFromRes( IDS_FILTER_POSTPROCESSFILES, /*r*/strFilter );
  16. CFileDialog dlg( TRUE,
  17. NULL,
  18. NULL,
  19. OFN_ENABLESIZING | OFN_EXPLORER | OFN_NOREADONLYRETURN | OFN_FILEMUSTEXIST,
  20. strFilter,
  21. m_hWnd );
  22. if ( dlg.DoModal() == IDCANCEL ) return 0;
  23. // File names must be unique as the path is not preserved
  24. // Check if there is already a file with the same name
  25. WCHAR wszNew[ MAX_PATH + 1 ];
  26. ::wcscpy( wszNew, dlg.m_szFileName );
  27. ::PathStripPath( wszNew );
  28. for ( TStringList::const_iterator it = m_Files.begin();
  29. it != m_Files.end();
  30. ++it )
  31. {
  32. WCHAR wszCurrent[ MAX_PATH + 1 ];
  33. ::wcscpy( wszCurrent, it->c_str() );
  34. ::PathStripPathW( wszCurrent );
  35. if ( ::_wcsicmp( wszCurrent, wszNew ) == 0 )
  36. {
  37. UIUtils::MessageBox( m_hWnd, IDS_E_PPFILENOTUNIQUE, IDS_APPTITLE, MB_OK | MB_ICONSTOP );
  38. return 0 ;
  39. }
  40. }
  41. m_Files.push_back( std::wstring( dlg.m_szFileName ) );
  42. ::wcscpy( wszNew, dlg.m_szFileName );
  43. UIUtils::PathCompatCtrlWidth( GetDlgItem( IDC_FILES ), wszNew, ::GetSystemMetrics( SM_CXVSCROLL ) );
  44. ListBox_AddString( GetDlgItem( IDC_FILES ), wszNew );
  45. return 0;
  46. }
  47. LRESULT CPostProcessAdd::OnDelFile( WORD wNotifyCode, WORD /*wID*/, HWND hWndCtl, BOOL& bHandled )
  48. {
  49. HWND hwndFiles = GetDlgItem( IDC_FILES );
  50. int nCurSel = ListBox_GetCurSel( hwndFiles );
  51. _ASSERT( nCurSel != LB_ERR );
  52. ListBox_DeleteString( hwndFiles, nCurSel );
  53. if ( ListBox_GetCount( hwndFiles ) > 0 )
  54. {
  55. ListBox_SetCurSel( hwndFiles, max( nCurSel - 1, 0 ) );
  56. }
  57. else
  58. {
  59. ::EnableWindow( hWndCtl, FALSE );
  60. }
  61. return 0;
  62. }
  63. LRESULT CPostProcessAdd::LBSelChanged( WORD /*wNotifyCode*/, WORD wID, HWND hWndCtl, BOOL& /*bHandled*/ )
  64. {
  65. // If selection is not changed - do nothing
  66. if ( ListBox_GetCurSel( hWndCtl ) == LB_ERR ) return 0;
  67. if ( wID == IDC_FILES )
  68. {
  69. ::EnableWindow( GetDlgItem( IDC_DELFILE ), TRUE );
  70. }
  71. else if ( wID == IDC_COMMANDS )
  72. {
  73. ::EnableWindow( GetDlgItem( IDC_DELCMD ), TRUE );
  74. ::EnableWindow( GetDlgItem( IDC_EDITCMD ), TRUE );
  75. int iLastEl = ListBox_GetCount( hWndCtl ) - 1;
  76. int iCurSel = ListBox_GetCurSel( hWndCtl );
  77. _ASSERT( iCurSel != LB_ERR );
  78. // Enable / Disable the MoveUp and MoveDown Btns
  79. ::EnableWindow( GetDlgItem( IDC_MOVEUP ), iCurSel > 0 );
  80. ::EnableWindow( GetDlgItem( IDC_MOVEDOWN ), iCurSel < iLastEl );
  81. }
  82. return 0;
  83. }
  84. LRESULT CPostProcessAdd::OnAddCmd( WORD wNotifyCode, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled )
  85. {
  86. CCommandDlg dlg;
  87. if ( dlg.DoModal() != IDOK ) return 0;
  88. CmdInfo Cmd;
  89. Cmd.bIgnoreErrors = dlg.m_bIgnoreErrors;
  90. Cmd.dwTimeout = dlg.m_dwTimeout;
  91. Cmd.strText = dlg.m_strText;
  92. m_Commands.push_back( Cmd );
  93. UIUtils::TrimTextToCtrl( GetDlgItem( IDC_COMMANDS ),
  94. dlg.m_strText.GetBuffer( dlg.m_strText.GetLength() ),
  95. ::GetSystemMetrics( SM_CXVSCROLL ) );
  96. dlg.m_strText.ReleaseBuffer();
  97. BOOL bUnused = FALSE;;
  98. ListBox_InsertString( GetDlgItem( IDC_COMMANDS ), -1, dlg.m_strText );
  99. LBSelChanged( LBN_SELCHANGE, IDC_COMMANDS, GetDlgItem( IDC_COMMANDS ), bUnused );
  100. return 0;
  101. }
  102. LRESULT CPostProcessAdd::OnDelCmd( WORD wNotifyCode, WORD /*wID*/, HWND hWndCtl, BOOL& bHandled )
  103. {
  104. HWND hwndCmds = GetDlgItem( IDC_COMMANDS );
  105. int nCurSel = ListBox_GetCurSel( hwndCmds );
  106. _ASSERT( nCurSel != LB_ERR );
  107. ListBox_DeleteString( hwndCmds, nCurSel );
  108. m_Commands.erase( m_Commands.begin() + nCurSel );
  109. if ( ListBox_GetCount( hwndCmds ) > 0 )
  110. {
  111. BOOL bUnused = FALSE;
  112. ListBox_SetCurSel( hwndCmds, max( nCurSel - 1, 0 ) );
  113. LBSelChanged( LBN_SELCHANGE, IDC_COMMANDS, GetDlgItem( IDC_COMMANDS ), bUnused );
  114. }
  115. else
  116. {
  117. ::EnableWindow( hWndCtl, FALSE );
  118. ::EnableWindow( GetDlgItem( IDC_EDITCMD ), FALSE );
  119. }
  120. return 0;
  121. }
  122. LRESULT CPostProcessAdd::OnEditCmd( WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/ )
  123. {
  124. HWND hwndCmds = GetDlgItem( IDC_COMMANDS );
  125. int iCmd = ListBox_GetCurSel( hwndCmds );
  126. if ( LB_ERR == iCmd ) return 0;
  127. CCommandDlg dlg;
  128. dlg.m_bIgnoreErrors = m_Commands[ iCmd ].bIgnoreErrors;
  129. dlg.m_dwTimeout = m_Commands[ iCmd ].dwTimeout;
  130. dlg.m_strText = m_Commands[ iCmd ].strText;
  131. if ( dlg.DoModal() != IDOK ) return 0;
  132. m_Commands[ iCmd ].bIgnoreErrors = dlg.m_bIgnoreErrors;
  133. m_Commands[ iCmd ].dwTimeout = dlg.m_dwTimeout;
  134. m_Commands[ iCmd ].strText = dlg.m_strText;
  135. UIUtils::TrimTextToCtrl( hwndCmds,
  136. dlg.m_strText.GetBuffer( dlg.m_strText.GetLength() ),
  137. ::GetSystemMetrics( SM_CXVSCROLL ) );
  138. dlg.m_strText.ReleaseBuffer();
  139. ListBox_InsertString( hwndCmds, iCmd, dlg.m_strText );
  140. ListBox_DeleteString( hwndCmds, iCmd + 1 );
  141. ListBox_SetCurSel( hwndCmds, iCmd );
  142. return 0;
  143. }
  144. LRESULT CPostProcessAdd::LBDoubleClick( WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/ )
  145. {
  146. if ( wID != IDC_COMMANDS ) return 0;
  147. BOOL bUnused = FALSE;
  148. OnEditCmd( BN_CLICKED, IDC_EDITCMD, GetDlgItem( IDC_EDITCMD ), bUnused );
  149. return 0;
  150. }
  151. LRESULT CPostProcessAdd::OnMoveUp( WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/ )
  152. {
  153. HWND hwndCmds = GetDlgItem( IDC_COMMANDS );
  154. int iSel = ListBox_GetCurSel( hwndCmds );
  155. _ASSERT( ( iSel != LB_ERR ) && ( iSel > 0 ) );
  156. LBSwapElements( hwndCmds, iSel, iSel - 1 );
  157. ListBox_SetCurSel( hwndCmds, iSel - 1 );
  158. BOOL bUnused = FALSE;
  159. LBSelChanged( LBN_SELCHANGE, IDC_COMMANDS, GetDlgItem( IDC_COMMANDS ), bUnused );
  160. CmdInfo cmdTemp = m_Commands[ iSel ];
  161. m_Commands[ iSel ] = m_Commands[ iSel - 1 ];
  162. m_Commands[ iSel - 1 ] = cmdTemp;
  163. return 0;
  164. }
  165. LRESULT CPostProcessAdd::OnMoveDown( WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/ )
  166. {
  167. HWND hwndCmds = GetDlgItem( IDC_COMMANDS );
  168. int iSel = ListBox_GetCurSel( hwndCmds );
  169. _ASSERT( ( iSel != LB_ERR ) && ( iSel < ( ListBox_GetCount( hwndCmds ) - 1 ) ) );
  170. LBSwapElements( hwndCmds, iSel, iSel + 1 );
  171. ListBox_SetCurSel( hwndCmds, iSel + 1 );
  172. BOOL bUnused = FALSE;
  173. LBSelChanged( LBN_SELCHANGE, IDC_COMMANDS, GetDlgItem( IDC_COMMANDS ), bUnused );
  174. CmdInfo cmdTemp = m_Commands[ iSel ];
  175. m_Commands[ iSel ] = m_Commands[ iSel + 1 ];
  176. m_Commands[ iSel + 1 ] = cmdTemp;
  177. return 0;
  178. }
  179. void CPostProcessAdd::LBSwapElements( HWND hwndLB, int iSrc, int iTarget )
  180. {
  181. _ASSERT( hwndLB != NULL );
  182. _ASSERT( iSrc != iTarget );
  183. CString strSrc;
  184. CString strTarget;
  185. ListBox_GetText( hwndLB, iSrc, strSrc.GetBuffer( ListBox_GetTextLen( hwndLB, iSrc ) + 1 ) );
  186. ListBox_GetText( hwndLB, iTarget, strTarget.GetBuffer( ListBox_GetTextLen( hwndLB, iTarget ) + 1 ) );
  187. strSrc.ReleaseBuffer();
  188. strTarget.ReleaseBuffer();
  189. ListBox_InsertString( hwndLB, iTarget, strSrc );
  190. ListBox_DeleteString( hwndLB, iTarget + 1 );
  191. ListBox_InsertString( hwndLB, iSrc, strTarget );
  192. ListBox_DeleteString( hwndLB, iSrc + 1 );
  193. }
  194. int CPostProcessAdd::OnWizardNext()
  195. {
  196. int nRet = 0; // Goto next page
  197. int nMsgRes = 0;
  198. // Check if there are files, but no commands
  199. if ( m_Commands.empty() && !m_Files.empty() )
  200. {
  201. nMsgRes = UIUtils::MessageBox( m_hWnd, IDS_W_NOCMDS, IDS_APPTITLE, MB_YESNO | MB_ICONWARNING );
  202. // User wants to continue and ignore the files
  203. if ( IDYES == nMsgRes )
  204. {
  205. m_Files.clear();
  206. ListBox_ResetContent( GetDlgItem( IDC_FILES ) );
  207. }
  208. else
  209. {
  210. nRet = -1; // Stay on this page
  211. }
  212. }
  213. return nRet;
  214. }