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.

578 lines
13 KiB

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