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.

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