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.

553 lines
14 KiB

  1. //
  2. // Copyright 1997 - Microsoft
  3. //
  4. // TOOLS.CPP - Handles the "Tools" IDD_PROP_TOOLS tab
  5. //
  6. #include "pch.h"
  7. #include "utils.h"
  8. #include "cservice.h"
  9. #include "cenumsif.h"
  10. #include "tools.h"
  11. #include "ccomputr.h"
  12. #include "sifprop.h"
  13. DEFINE_MODULE("IMADMUI")
  14. DEFINE_THISCLASS("CToolsTab")
  15. #define THISCLASS CToolsTab
  16. #define LPTHISCLASS CToolsTab*
  17. #define NUM_COLUMNS 3
  18. DWORD aToolsHelpMap[] = {
  19. IDC_L_TOOLS, HIDC_L_TOOLS,
  20. IDC_B_REMOVE, HIDC_B_REMOVE,
  21. IDC_B_PROPERTIES, HIDC_B_PROPERTIES,
  22. IDC_B_REFRESH, HIDC_B_REFRESH,
  23. NULL, NULL
  24. };
  25. //
  26. // CreateInstance()
  27. //
  28. LPVOID
  29. CToolsTab_CreateInstance( void )
  30. {
  31. TraceFunc( "CToolsTab_CreateInstance()\n" );
  32. LPTHISCLASS lpcc = new THISCLASS( );
  33. HRESULT hr = THR( lpcc->Init( ) );
  34. if ( FAILED(hr)) {
  35. delete lpcc;
  36. RETURN(NULL);
  37. }
  38. RETURN((LPVOID) lpcc);
  39. }
  40. //
  41. // Constructor
  42. //
  43. THISCLASS::THISCLASS( ) :
  44. _hDlg(NULL),
  45. _punkService(NULL),
  46. _fAdmin(FALSE),
  47. _hNotify(NULL)
  48. {
  49. TraceClsFunc( "CToolsTab()\n" );
  50. InterlockIncrement( g_cObjects );
  51. TraceFuncExit();
  52. }
  53. //
  54. // Init()
  55. //
  56. STDMETHODIMP
  57. THISCLASS::Init( )
  58. {
  59. HRESULT hr = S_OK;
  60. TraceClsFunc( "Init()\n" );
  61. HRETURN(hr);
  62. }
  63. //
  64. // Destructor
  65. //
  66. THISCLASS::~THISCLASS( )
  67. {
  68. TraceClsFunc( "~CToolsTab()\n" );
  69. if ( _punkService )
  70. _punkService->Release( );
  71. // tell ADS to destroy the notify object
  72. // NOTE: Another property page may do this before us. Ignore errors.
  73. SendMessage( _hNotify, WM_ADSPROP_NOTIFY_EXIT, 0, 0 );
  74. InterlockDecrement( g_cObjects );
  75. TraceFuncExit();
  76. };
  77. // *************************************************************************
  78. //
  79. // ITab
  80. //
  81. // *************************************************************************
  82. STDMETHODIMP
  83. THISCLASS::AddPages(
  84. LPFNADDPROPSHEETPAGE lpfnAddPage,
  85. LPARAM lParam,
  86. LPUNKNOWN punk )
  87. {
  88. TraceClsFunc( "AddPages( )\n" );
  89. HRESULT hr = S_OK;
  90. PROPSHEETPAGE psp;
  91. HPROPSHEETPAGE hpage;
  92. psp.dwSize = sizeof(psp);
  93. psp.dwFlags = PSP_USEREFPARENT | PSP_USECALLBACK;
  94. psp.hInstance = (HINSTANCE) g_hInstance;
  95. psp.pszTemplate = MAKEINTRESOURCE(IDD_PROP_TOOLS);
  96. psp.pcRefParent = (UINT *) &g_cObjects;
  97. psp.pfnCallback = (LPFNPSPCALLBACK) PropSheetPageProc;
  98. psp.pfnDlgProc = PropSheetDlgProc;
  99. psp.lParam = (LPARAM) this;
  100. hpage = CreatePropertySheetPage( &psp );
  101. if ( hpage ) {
  102. if ( !lpfnAddPage( hpage, lParam ) ) {
  103. DestroyPropertySheetPage( hpage );
  104. hr = E_FAIL;
  105. goto Error;
  106. }
  107. }
  108. punk->AddRef( ); // matching Release in the destructor
  109. _punkService = punk;
  110. Error:
  111. HRETURN(hr);
  112. }
  113. //
  114. // ReplacePage()
  115. //
  116. STDMETHODIMP
  117. THISCLASS::ReplacePage(
  118. UINT uPageID,
  119. LPFNADDPROPSHEETPAGE lpfnReplaceWith,
  120. LPARAM lParam,
  121. LPUNKNOWN punk )
  122. {
  123. TraceClsFunc( "ReplacePage( ) *** NOT_IMPLEMENTED ***\n" );
  124. RETURN(E_NOTIMPL);
  125. }
  126. //
  127. // QueryInformation( )
  128. //
  129. STDMETHODIMP
  130. THISCLASS::QueryInformation(
  131. LPWSTR pszAttribute,
  132. LPWSTR * pszResult )
  133. {
  134. TraceClsFunc( "QueryInformation( )\n" );
  135. HRETURN(E_NOTIMPL);
  136. }
  137. //
  138. // AllowActivation( )
  139. //
  140. STDMETHODIMP
  141. THISCLASS::AllowActivation(
  142. BOOL * pfAllow )
  143. {
  144. TraceClsFunc( "AllowActivation( )\n" );
  145. HRETURN(E_NOTIMPL);
  146. }
  147. // ************************************************************************
  148. //
  149. // Property Sheet Functions
  150. //
  151. // ************************************************************************
  152. //
  153. // _InitDialog( )
  154. //
  155. HRESULT
  156. THISCLASS::_InitDialog(
  157. HWND hDlg,
  158. LPARAM lParam )
  159. {
  160. TraceClsFunc( "_InitDialog( )\n" );
  161. CWaitCursor Wait;
  162. HRESULT hr = S_OK;
  163. HWND hwndList;
  164. IIntelliMirrorSAP * pimsap = NULL;
  165. IEnumIMSIFs * penum = NULL;
  166. LV_COLUMN lvC;
  167. INT iCount;
  168. WCHAR szText[ 64 ];
  169. UINT uColumnWidths[NUM_COLUMNS] = { 225, 75, 75};
  170. if ( hDlg ) {
  171. _hDlg = hDlg;
  172. }
  173. hwndList = GetDlgItem( _hDlg, IDC_L_TOOLS );
  174. Assert( _punkService );
  175. hr = THR( _punkService->QueryInterface( IID_IIntelliMirrorSAP, (void**) &pimsap ) );
  176. if (FAILED(hr)) {
  177. Assert( _fAdmin == FALSE );
  178. goto Error;
  179. }
  180. hr = THR( pimsap->GetNotifyWindow( &_hNotify ) );
  181. if (FAILED( hr )) {
  182. goto Error;
  183. }
  184. ADsPropSetHwnd( _hNotify, _hDlg );
  185. hr = THR( pimsap->IsAdmin( &_fAdmin ) );
  186. if (FAILED(hr)) {
  187. Assert( _fAdmin == FALSE );
  188. }
  189. hr = THR( pimsap->EnumTools( ENUM_READ, (LPUNKNOWN*)&penum ) );
  190. if (FAILED(hr)) {
  191. Assert( _fAdmin == FALSE );
  192. goto Error;
  193. }
  194. ListView_DeleteAllItems( hwndList );
  195. // Create the columns
  196. lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  197. lvC.fmt = LVCFMT_LEFT;
  198. lvC.pszText = szText;
  199. // Add the columns.
  200. for ( iCount = 0; iCount < NUM_COLUMNS; iCount++ ) {
  201. INT i;
  202. lvC.iSubItem = iCount;
  203. lvC.cx = uColumnWidths[iCount];
  204. if (!LoadString( g_hInstance, IDS_OS_COLUMN1 + iCount, szText, ARRAYSIZE (szText) ) ||
  205. -1 == ListView_InsertColumn ( hwndList, iCount, &lvC )) {
  206. hr = E_FAIL;
  207. goto Error;
  208. }
  209. }
  210. if (FAILED(hr = PopulateListView( hwndList, penum ))) {
  211. MessageBoxFromStrings( _hDlg,
  212. IDS_COULDNOTCONTACTSERVER_CAPTION,
  213. IDS_COULDNOTCONTACTSERVER_TEXT,
  214. MB_OK | MB_ICONERROR );
  215. }
  216. Cleanup:
  217. if ( penum )
  218. penum->Release( );
  219. if ( pimsap )
  220. pimsap->Release( );
  221. EnableWindow( hwndList, _fAdmin );
  222. HRETURN(hr);
  223. Error:
  224. MessageBoxFromHResult( _hDlg, IDS_ERROR_OPENNINGGROUPOBJECT, hr );
  225. goto Cleanup;
  226. }
  227. //
  228. // _OnSelectionChanged( )
  229. //
  230. HRESULT
  231. THISCLASS::_OnSelectionChanged( )
  232. {
  233. TraceClsFunc( "_OnSelectionChanged( )\n" );
  234. HRESULT hr = S_OK;
  235. UINT iItems = ListView_GetSelectedCount( GetDlgItem( _hDlg, IDC_L_TOOLS ) );
  236. EnableWindow( GetDlgItem( _hDlg, IDC_B_REMOVE ), !!iItems );
  237. EnableWindow( GetDlgItem( _hDlg, IDC_B_PROPERTIES ), !!iItems );
  238. HRETURN( hr );
  239. }
  240. //
  241. // _OnCommand( )
  242. //
  243. HRESULT
  244. THISCLASS::_OnCommand( WPARAM wParam, LPARAM lParam )
  245. {
  246. TraceClsFunc( "_OnCommand( " );
  247. TraceMsg( TF_FUNC, "wParam = 0x%08x, lParam = 0x%08x )\n", wParam, lParam );
  248. HRESULT hr = S_FALSE;
  249. HWND hwndCtl = (HWND) lParam;
  250. switch ( LOWORD(wParam) ) {
  251. case IDC_B_PROPERTIES:
  252. if ( HIWORD( wParam ) == BN_CLICKED ) {
  253. LVITEM lvi;
  254. HWND hwndList = GetDlgItem( _hDlg, IDC_L_TOOLS );
  255. lvi.iItem = ListView_GetNextItem( hwndList, -1, LVNI_SELECTED );
  256. if ( lvi.iItem != -1 ) {
  257. lvi.iSubItem = 0;
  258. lvi.mask = LVIF_PARAM;
  259. ListView_GetItem( hwndList, &lvi );
  260. Assert(lvi.lParam);
  261. hr = CSifProperties_CreateInstance( _hDlg, MAKEINTRESOURCE(IDD_SIF_PROP_TOOLS), (LPSIFINFO) lvi.lParam );
  262. }
  263. }
  264. break;
  265. case IDC_B_REFRESH:
  266. if ( HIWORD( wParam ) == BN_CLICKED ) {
  267. hr = S_OK;
  268. }
  269. break;
  270. case IDC_B_REMOVE:
  271. if ( HIWORD( wParam ) == BN_CLICKED ) {
  272. LVITEM lvi;
  273. UINT iResult;
  274. HWND hwndList = GetDlgItem( _hDlg, IDC_L_TOOLS );
  275. lvi.iItem = ListView_GetNextItem( hwndList, -1, LVNI_SELECTED );
  276. iResult = MessageBoxFromStrings( _hDlg, IDS_AREYOUSURE_CAPTION, IDS_DELETESIF_TEXT, MB_YESNO );
  277. if ( iResult == IDYES ) {
  278. if ( lvi.iItem != -1 ) {
  279. LPSIFINFO psif;
  280. lvi.iSubItem = 0;
  281. lvi.mask = LVIF_PARAM;
  282. ListView_GetItem( hwndList, &lvi );
  283. psif = (LPSIFINFO)lvi.lParam;
  284. if ( !DeleteFile( psif->pszFilePath ) ) {
  285. ::MessageBoxFromError( _hDlg, 0, GetLastError() );
  286. } else {
  287. ListView_DeleteItem( hwndList, lvi.iItem );
  288. hr = S_OK;
  289. }
  290. }
  291. }
  292. }
  293. break;
  294. }
  295. if ( hr == S_OK ) {
  296. HWND hwndList = GetDlgItem(_hDlg, IDC_L_TOOLS);
  297. IIntelliMirrorSAP * pimsap = NULL;
  298. hr = THR( _punkService->QueryInterface( IID_IIntelliMirrorSAP, (void**) &pimsap ) );
  299. if (hr == S_OK) {
  300. LPENUMSIFS penum = NULL;
  301. hr = THR( pimsap->EnumTools( ENUM_READ, (LPUNKNOWN*)&penum ) );
  302. if ( hr == S_OK ) {
  303. hr = PopulateListView( hwndList, penum);
  304. penum->Release();
  305. }
  306. pimsap->Release();
  307. }
  308. // See if we still have a selection
  309. _OnSelectionChanged( );
  310. }
  311. HRETURN(hr);
  312. }
  313. //
  314. // _OnNotify( )
  315. //
  316. INT
  317. THISCLASS::_OnNotify(
  318. WPARAM wParam,
  319. LPARAM lParam )
  320. {
  321. TraceClsFunc( "_OnNotify( " );
  322. TraceMsg( TF_FUNC, "wParam = 0x%08x, lParam = 0x%08x )\n", wParam, lParam );
  323. LPNMHDR lpnmhdr = (LPNMHDR) lParam;
  324. switch ( lpnmhdr->code ) {
  325. case PSN_APPLY:
  326. TraceMsg( TF_WM, TEXT("WM_NOTIFY: PSN_APPLY\n"));
  327. // Tell DSA that someone hit Apply
  328. SendMessage( _hNotify, WM_ADSPROP_NOTIFY_APPLY, 0, 0 );
  329. SetWindowLongPtr( _hDlg, DWLP_MSGRESULT, PSNRET_NOERROR );
  330. RETURN(TRUE);
  331. case LVN_ITEMCHANGED:
  332. {
  333. _OnSelectionChanged( );
  334. }
  335. break;
  336. case LVN_DELETEALLITEMS:
  337. DebugMsg( "LVN_DELETEALLITEMS - Deleting all items.\n" );
  338. RETURN(FALSE);
  339. case LVN_DELETEITEM:
  340. {
  341. LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;
  342. LPSIFINFO psif = (LPSIFINFO) pnmv->lParam;
  343. Assert( psif );
  344. if ( psif ) {
  345. if (psif->pszArchitecture) {
  346. TraceFree( psif->pszArchitecture );
  347. }
  348. if (psif->pszDescription) {
  349. TraceFree( psif->pszDescription );
  350. }
  351. if (psif->pszDirectory) {
  352. TraceFree( psif->pszDirectory );
  353. }
  354. if (psif->pszFilePath) {
  355. TraceFree( psif->pszFilePath );
  356. }
  357. if (psif->pszHelpText) {
  358. TraceFree( psif->pszHelpText );
  359. }
  360. if (psif->pszImageType) {
  361. TraceFree( psif->pszImageType );
  362. }
  363. if (psif->pszLanguage) {
  364. TraceFree( psif->pszLanguage );
  365. }
  366. if (psif->pszVersion) {
  367. TraceFree( psif->pszVersion );
  368. }
  369. if (psif->pszImageFile) {
  370. TraceFree( psif->pszImageFile );
  371. }
  372. TraceFree( psif );
  373. }
  374. }
  375. break;
  376. }
  377. RETURN(FALSE);
  378. }
  379. //
  380. // PropSheetDlgProc()
  381. //
  382. INT_PTR CALLBACK
  383. THISCLASS::PropSheetDlgProc(
  384. HWND hDlg,
  385. UINT uMsg,
  386. WPARAM wParam,
  387. LPARAM lParam )
  388. {
  389. //TraceMsg( TEXT("PropSheetDlgProc(") );
  390. //TraceMsg( TF_FUNC, TEXT(" hDlg = 0x%08x, uMsg = 0x%08x, wParam = 0x%08x, lParam = 0x%08x )\n"),
  391. // hDlg, uMsg, wParam, lParam );
  392. LPTHISCLASS pcc = (LPTHISCLASS) GetWindowLongPtr( hDlg, GWLP_USERDATA );
  393. if ( uMsg == WM_INITDIALOG ) {
  394. TraceMsg( TF_WM, TEXT("WM_INITDIALOG\n"));
  395. LPPROPSHEETPAGE psp = (LPPROPSHEETPAGE) lParam;
  396. SetWindowLongPtr( hDlg, GWLP_USERDATA, psp->lParam );
  397. pcc = (LPTHISCLASS) psp->lParam;
  398. pcc->_InitDialog( hDlg, lParam );
  399. }
  400. if (pcc) {
  401. Assert( hDlg == pcc->_hDlg );
  402. switch ( uMsg ) {
  403. case WM_NOTIFY:
  404. pcc->_OnNotify( wParam, lParam );
  405. break;
  406. case WM_COMMAND:
  407. TraceMsg( TF_WM, TEXT("WM_COMMAND\n") );
  408. pcc->_OnCommand( wParam, lParam );
  409. break;
  410. case WM_HELP:// F1
  411. {
  412. LPHELPINFO phelp = (LPHELPINFO) lParam;
  413. WinHelp( (HWND) phelp->hItemHandle, g_cszHelpFile, HELP_WM_HELP, (DWORD_PTR) &aToolsHelpMap );
  414. }
  415. break;
  416. case WM_CONTEXTMENU: // right mouse click
  417. WinHelp((HWND) wParam, g_cszHelpFile, HELP_CONTEXTMENU, (DWORD_PTR) &aToolsHelpMap );
  418. break;
  419. case WM_ADSPROP_PAGE_GET_NOTIFY:
  420. {
  421. HWND *phwnd = (HWND *) wParam;
  422. *phwnd = pcc->_hNotify;
  423. }
  424. return TRUE;
  425. }
  426. }
  427. return FALSE;
  428. }
  429. //
  430. // PropSheetPageProc()
  431. //
  432. UINT CALLBACK
  433. THISCLASS::PropSheetPageProc(
  434. HWND hwnd,
  435. UINT uMsg,
  436. LPPROPSHEETPAGE ppsp )
  437. {
  438. TraceClsFunc( "PropSheetPageProc( " );
  439. TraceMsg( TF_FUNC, TEXT("hwnd = 0x%08x, uMsg = 0x%08x, ppsp= 0x%08x )\n"),
  440. hwnd, uMsg, ppsp );
  441. switch ( uMsg ) {
  442. case PSPCB_CREATE:
  443. RETURN(TRUE); // create it
  444. break;
  445. case PSPCB_RELEASE:
  446. LPTHISCLASS pcc = (LPTHISCLASS) ppsp->lParam;
  447. delete pcc;
  448. break;
  449. }
  450. RETURN(FALSE);
  451. }