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.

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