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.

1812 lines
49 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. //
  3. // 08/13/98
  4. // alhen
  5. //
  6. #include "stdafx.h"
  7. #include "tscc.h"
  8. #include "compdata.h"
  9. #include "comp.h"
  10. #include "tsprsht.h"
  11. #include "sdlgs.h"
  12. INT_PTR CALLBACK RenameDlgProc( HWND , UINT , WPARAM , LPARAM );
  13. void ErrMessage( HWND hwndOwner , INT_PTR iResourceID );
  14. extern void xxxErrMessage( HWND hwnd , INT_PTR nResMessageId , INT_PTR nResTitleId , UINT nFlags );
  15. extern void TscAccessDeniedMsg( HWND hwnd );
  16. extern void TscGeneralErrMsg( HWND hwnd );
  17. BOOL IsValidConnectionName( LPTSTR szConName , PDWORD );
  18. extern void SnodeErrorHandler( HWND hParent , INT nObjectId , DWORD dwStatus );
  19. extern void ReportStatusError( HWND hwnd , DWORD dwStatus );
  20. extern BOOL g_bAppSrvMode;
  21. //extern BOOL g_bEditMode;
  22. //--------------------------------------------------------------------------
  23. CComp::CComp( CCompdata* pCompdata )
  24. {
  25. m_pConsole = NULL;
  26. m_pCompdata = pCompdata;
  27. m_pResultData = NULL;
  28. m_pHeaderCtrl = NULL;
  29. m_pConsoleVerb = NULL;
  30. m_pImageResult = NULL;
  31. m_pDisplayHelp = NULL;
  32. m_nSettingCol = 0;
  33. m_nAttribCol = 0;
  34. m_cRef = 1; // addref at ctor
  35. }
  36. //--------------------------------------------------------------------------
  37. CComp::~CComp( )
  38. {
  39. }
  40. //--------------------------------------------------------------------------
  41. STDMETHODIMP CComp::QueryInterface( REFIID riid , PVOID *ppv )
  42. {
  43. HRESULT hr = S_OK;
  44. if( riid == IID_IUnknown )
  45. {
  46. *ppv = ( LPUNKNOWN )( LPCOMPONENT )this;
  47. }
  48. else if( riid == IID_IComponent )
  49. {
  50. *ppv = ( LPCOMPONENT )this;
  51. }
  52. else if( riid == IID_IExtendContextMenu )
  53. {
  54. *ppv = ( LPEXTENDCONTEXTMENU )this;
  55. }
  56. else if( riid == IID_IExtendPropertySheet )
  57. {
  58. *ppv = ( LPEXTENDPROPERTYSHEET )this;
  59. }
  60. else
  61. {
  62. *ppv = 0;
  63. hr = E_NOINTERFACE;
  64. }
  65. AddRef( );
  66. return hr;
  67. }
  68. //--------------------------------------------------------------------------
  69. STDMETHODIMP_( ULONG ) CComp::AddRef( )
  70. {
  71. return InterlockedIncrement( ( LPLONG )&m_cRef );
  72. }
  73. //--------------------------------------------------------------------------
  74. STDMETHODIMP_( ULONG )CComp::Release( )
  75. {
  76. if( InterlockedDecrement( ( LPLONG )&m_cRef ) == 0 )
  77. {
  78. delete this;
  79. return 0;
  80. }
  81. return m_cRef;
  82. }
  83. //--------------------------------------------------------------------------
  84. STDMETHODIMP CComp::Initialize( LPCONSOLE lpConsole )
  85. {
  86. HRESULT hr;
  87. ASSERT( lpConsole != NULL );
  88. m_pConsole = lpConsole;
  89. m_pConsole->AddRef( );
  90. // VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_MAINFOLDERNAME , m_strDispName , sizeof( m_strDispName ) ) );
  91. do
  92. {
  93. if( FAILED( ( hr = m_pConsole->QueryInterface( IID_IResultData , ( LPVOID *)&m_pResultData ) ) ) )
  94. {
  95. break;
  96. }
  97. if( FAILED( ( hr = m_pConsole->QueryInterface( IID_IHeaderCtrl , ( LPVOID *)&m_pHeaderCtrl ) ) ) )
  98. {
  99. break;
  100. }
  101. if( FAILED( ( hr = m_pConsole->QueryConsoleVerb( &m_pConsoleVerb ) ) ) )
  102. {
  103. break;
  104. }
  105. if( FAILED( ( hr = m_pConsole->QueryInterface( IID_IDisplayHelp , ( LPVOID * )&m_pDisplayHelp ) ) ) )
  106. {
  107. break;
  108. }
  109. hr = m_pConsole->QueryResultImageList( &m_pImageResult );
  110. }while( 0 );
  111. return hr;
  112. }
  113. //--------------------------------------------------------------------------
  114. STDMETHODIMP CComp::Notify( LPDATAOBJECT pDataObj , MMC_NOTIFY_TYPE event , LPARAM arg , LPARAM )
  115. {
  116. switch( event )
  117. {
  118. case MMCN_ACTIVATE:
  119. ODS( L"IComponent -- MMCN_ACTIVATE\n" );
  120. //Bug 483485 - we want to call OnRefresh so that MMC can get the current window's pointer list. The
  121. //only reason this problem wasn't seen more often is that OnShow is called when one of the left nodes
  122. //is clicked on which does something similar to OnRefresh, so it was masking the problem. This isn't
  123. //sufficient when accessing the result nodes immediately after switching windows though
  124. if (arg) //We only refresh the activated node. This is also called for deactivation with arg = false
  125. OnRefresh(pDataObj);
  126. break;
  127. case MMCN_ADD_IMAGES:
  128. ODS( L"IComponent -- MMCN_ADD_IMAGES\n" );
  129. OnAddImages( );
  130. break;
  131. case MMCN_BTN_CLICK:
  132. ODS( L"IComponent -- MMCN_BTN_CLICK\n" );
  133. break;
  134. case MMCN_CLICK:
  135. ODS( L"IComponent -- MMCN_CLICK\n" );
  136. break;
  137. case MMCN_DBLCLICK:
  138. ODS( L"IComponent -- MMCN_DBLCLICK\n" );
  139. // enables navigation to inner folders.
  140. // final item launches default verb
  141. OnDblClk( pDataObj );
  142. return S_FALSE;
  143. case MMCN_DELETE:
  144. ODS( L"IComponent -- MMCN_DELETE\n" );
  145. OnDelete( pDataObj );
  146. break;
  147. case MMCN_EXPAND:
  148. ODS( L"IComponent -- MMCN_EXPAND\n" );
  149. break;
  150. case MMCN_MINIMIZED:
  151. ODS( L"IComponent -- MMCN_MINIMIZED\n" );
  152. break;
  153. case MMCN_PROPERTY_CHANGE:
  154. ODS( L"IComponent -- MMCN_PROPERTY_CHANGE\n" );
  155. break;
  156. case MMCN_REMOVE_CHILDREN:
  157. ODS( L"IComponent -- MMCN_REMOVE_CHILDREN\n" );
  158. break;
  159. case MMCN_REFRESH:
  160. ODS( L"IComponent -- MMCN_REFRESH\n" );
  161. OnRefresh( pDataObj );
  162. break;
  163. case MMCN_RENAME:
  164. ODS( L"IComponent -- MMCN_RENAME\n" );
  165. break;
  166. case MMCN_SELECT:
  167. ODS( L"IComponent -- MMCN_SELECT\n" );
  168. OnSelect( pDataObj , ( BOOL )LOWORD( arg ) , ( BOOL )HIWORD( arg ) );
  169. break;
  170. case MMCN_SHOW:
  171. ODS( L"IComponent -- MMCN_SHOW\n" );
  172. OnShow( pDataObj , ( BOOL )arg );
  173. break;
  174. case MMCN_VIEW_CHANGE:
  175. ODS( L"IComponent -- MMCN_VIEW_CHANGE\n" );
  176. OnViewChange( );
  177. break;
  178. case MMCN_CONTEXTHELP:
  179. ODS( L"IComponent -- MMCN_CONTEXTHELP\n" );
  180. OnHelp( pDataObj );
  181. break;
  182. case MMCN_SNAPINHELP:
  183. ODS( L"IComponent -- MMCN_SNAPINHELP\n" );
  184. break;
  185. default:
  186. ODS( L"CComp::Notify - event not registered\n" );
  187. }
  188. return S_OK;
  189. }
  190. //--------------------------------------------------------------------------
  191. // pDataobject represents the current selected scope folder
  192. // this should only be our main folder in the scope pane
  193. //--------------------------------------------------------------------------
  194. HRESULT CComp::OnShow( LPDATAOBJECT pDataobject , BOOL bSelect )
  195. {
  196. TCHAR tchBuffer[ 256 ];
  197. HRESULT hr = S_FALSE;
  198. ASSERT( pDataobject != NULL );
  199. if( bSelect && m_pCompdata->IsSettingsFolder( pDataobject ) )
  200. {
  201. // set up columns for services folder
  202. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_SETTINGS_COLUMN1 , tchBuffer , SIZE_OF_BUFFER( tchBuffer ) ) );
  203. if( m_nSettingCol == 0 && m_nAttribCol == 0 )
  204. {
  205. SetColumnsForSettingsPane( );
  206. }
  207. ODS( L"TSCC:Comp@OnShow inserting columns\n" );
  208. if( m_nSettingCol == 0 )
  209. {
  210. hr = m_pHeaderCtrl->InsertColumn( 0 , tchBuffer , 0 , MMCLV_AUTO );
  211. }
  212. else
  213. {
  214. hr = m_pHeaderCtrl->InsertColumn( 0 , tchBuffer , 0 , m_nSettingCol );
  215. }
  216. if( SUCCEEDED( hr ) )
  217. {
  218. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_ATTRIB_COLUMN2 , tchBuffer , SIZE_OF_BUFFER( tchBuffer ) ) );
  219. if( m_nAttribCol == 0 )
  220. {
  221. hr = m_pHeaderCtrl->InsertColumn( 1 , tchBuffer , 0 , MMCLV_AUTO );
  222. }
  223. else
  224. {
  225. hr = m_pHeaderCtrl->InsertColumn( 1 , tchBuffer , 0 , m_nAttribCol );
  226. }
  227. }
  228. AddSettingsinResultPane( );
  229. }
  230. else if( bSelect && m_pCompdata->IsConnectionFolder( pDataobject ) )
  231. {
  232. // set up column headers for connection folder
  233. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_COLCONNECT , tchBuffer , SIZE_OF_BUFFER( tchBuffer ) ) );
  234. hr = m_pHeaderCtrl->InsertColumn( 0 , tchBuffer , 0 , MMCLV_AUTO );
  235. if( SUCCEEDED( hr ) )
  236. {
  237. //SetColumnWidth( 0 );
  238. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_COLTRANSPORT , tchBuffer , SIZE_OF_BUFFER( tchBuffer ) ) );
  239. hr = m_pHeaderCtrl->InsertColumn( 1 , tchBuffer , 0 , MMCLV_AUTO );
  240. }
  241. if( SUCCEEDED( hr ) )
  242. {
  243. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_COLTYPE , tchBuffer , SIZE_OF_BUFFER( tchBuffer ) ) );
  244. // ui master dirty trick 120 equals fudge factor
  245. hr = m_pHeaderCtrl->InsertColumn( 2 , tchBuffer , 0 , 120/*MMCLV_AUTO*/ );
  246. }
  247. if( SUCCEEDED( hr ) )
  248. {
  249. //SetColumnWidth( 2 );
  250. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_COLCOMMENT , tchBuffer , SIZE_OF_BUFFER( tchBuffer ) ) );
  251. hr = m_pHeaderCtrl->InsertColumn( 3 , tchBuffer , 0 , MMCLV_AUTO );
  252. }
  253. // insert items
  254. if( SUCCEEDED( hr ) )
  255. {
  256. hr = InsertItemsinResultPane( );
  257. }
  258. }
  259. return hr;
  260. }
  261. //--------------------------------------------------------------------------
  262. BOOL CComp::OnAddImages( )
  263. {
  264. HICON hiconConnect = LoadIcon( _Module.GetResourceInstance( ) , MAKEINTRESOURCE( IDI_ICON_CON ) );
  265. HICON hiconDiscon = LoadIcon( _Module.GetResourceInstance( ) , MAKEINTRESOURCE( IDI_ICON_DISCON ) );
  266. HICON hiconBullet = LoadIcon( _Module.GetResourceInstance( ) , MAKEINTRESOURCE( IDI_ICON_BULLET ) );
  267. m_pImageResult->ImageListSetIcon( ( PLONG_PTR )hiconConnect , 1 );
  268. m_pImageResult->ImageListSetIcon( ( PLONG_PTR )hiconDiscon , 2 );
  269. m_pImageResult->ImageListSetIcon( ( PLONG_PTR )hiconBullet , 3 );
  270. return TRUE;
  271. }
  272. //--------------------------------------------------------------------------
  273. // update resultitems in result pane and note scopeitems
  274. //--------------------------------------------------------------------------
  275. BOOL CComp::OnViewChange( )
  276. {
  277. RESULTDATAITEM rdi;
  278. ZeroMemory( &rdi , sizeof( RESULTDATAITEM ) );
  279. rdi.mask = RDI_PARAM;
  280. m_pResultData->GetItem( &rdi );
  281. if( rdi.bScopeItem )
  282. {
  283. return FALSE;
  284. }
  285. if( SUCCEEDED( InsertItemsinResultPane( ) ) )
  286. {
  287. return TRUE;
  288. }
  289. return FALSE;
  290. }
  291. BOOL CComp::OnFullRefresh(LPDATAOBJECT pdo)
  292. {
  293. if (m_pCompdata->IsConnectionFolder(pdo))
  294. {
  295. if (!SUCCEEDED(InsertAndBuildItemsinResultPane()))
  296. return FALSE;
  297. }
  298. if (m_pCompdata->IsSettingsFolder(pdo))
  299. {
  300. if (!SUCCEEDED(AddSettingsinResultPane()))
  301. return FALSE;
  302. }
  303. return TRUE;
  304. }
  305. BOOL CComp::OnRefresh(LPDATAOBJECT pdo)
  306. {
  307. if (m_pCompdata->IsConnectionFolder(pdo))
  308. {
  309. if (!SUCCEEDED(InsertItemsinResultPane()))
  310. return FALSE;
  311. }
  312. if (m_pCompdata->IsSettingsFolder(pdo))
  313. {
  314. if (!SUCCEEDED(AddSettingsinResultPane()))
  315. return FALSE;
  316. }
  317. return TRUE;
  318. }
  319. //--------------------------------------------------------------------------
  320. STDMETHODIMP CComp::Destroy( MMC_COOKIE /* reserved */ )
  321. {
  322. ODS( L"IComponent releasing interfaces\n" );
  323. if( m_pResultData != NULL )
  324. {
  325. m_pResultData->Release( );
  326. }
  327. if( m_pConsole != NULL )
  328. {
  329. m_pConsole->Release( );
  330. }
  331. if( m_pHeaderCtrl != NULL )
  332. {
  333. m_pHeaderCtrl->Release( );
  334. }
  335. if( m_pConsoleVerb != NULL )
  336. {
  337. m_pConsoleVerb->Release( );
  338. }
  339. if( m_pImageResult != NULL )
  340. {
  341. m_pImageResult->Release( );
  342. }
  343. if( m_pDisplayHelp != NULL )
  344. {
  345. m_pDisplayHelp->Release( );
  346. }
  347. return S_OK;
  348. }
  349. //--------------------------------------------------------------------------
  350. STDMETHODIMP CComp::GetResultViewType( MMC_COOKIE , LPOLESTR* , PLONG plView )
  351. {
  352. *plView = MMC_VIEW_OPTIONS_NONE;
  353. return S_FALSE;
  354. }
  355. //--------------------------------------------------------------------------
  356. STDMETHODIMP CComp::QueryDataObject( MMC_COOKIE ck , DATA_OBJECT_TYPES dtype , LPDATAOBJECT* ppDataObject )
  357. {
  358. if( dtype == CCT_RESULT )
  359. {
  360. *ppDataObject = ( LPDATAOBJECT )ck;
  361. ( ( LPDATAOBJECT )*ppDataObject)->AddRef( );
  362. }
  363. else if( m_pCompdata != NULL )
  364. {
  365. return m_pCompdata->QueryDataObject( ck , dtype , ppDataObject );
  366. }
  367. return S_OK;
  368. }
  369. //--------------------------------------------------------------------------
  370. STDMETHODIMP CComp::GetDisplayInfo( LPRESULTDATAITEM pRdi )
  371. {
  372. ASSERT( pRdi != NULL );
  373. if( pRdi == NULL )
  374. {
  375. return E_INVALIDARG;
  376. }
  377. if( pRdi->bScopeItem )
  378. {
  379. CBaseNode *pScopeNode = ( CBaseNode * )pRdi->lParam;
  380. if( pScopeNode != NULL )
  381. {
  382. if( pScopeNode->GetNodeType( ) == MAIN_NODE )
  383. {
  384. //
  385. if( pRdi->mask & RDI_STR )
  386. {
  387. if( pRdi->nCol == 0 )
  388. {
  389. // pRdi->str is NULL in this call
  390. pRdi->str = ( LPOLESTR )m_pCompdata->m_tchMainFolderName; //m_strDispName;
  391. }
  392. }
  393. }
  394. else if( pScopeNode->GetNodeType( ) == SETTINGS_NODE )
  395. {
  396. if( pRdi->mask & RDI_STR )
  397. {
  398. if( pRdi->nCol == 0 )
  399. {
  400. // pRdi->str is NULL in this call
  401. pRdi->str = ( LPOLESTR )m_pCompdata->m_tchSettingsFolderName; //L"Server Settings";
  402. }
  403. }
  404. }
  405. }
  406. if( pRdi->mask & RDI_IMAGE )
  407. {
  408. ODS( TEXT("RDI_IMAGE -- in CComponent::GetDisplayInfo\n") );
  409. pRdi->nImage = ( ( CBaseNode * )pRdi->lParam )->GetImageIdx( );
  410. }
  411. }
  412. else
  413. {
  414. // populate result pane
  415. CBaseNode *pItem = ( CBaseNode * )pRdi->lParam;
  416. if( pItem != NULL )
  417. {
  418. if( pItem->GetNodeType( ) == RESULT_NODE )
  419. {
  420. CResultNode *pNode = ( CResultNode * )pRdi->lParam;
  421. if( pRdi->mask & RDI_STR )
  422. {
  423. switch( pRdi->nCol )
  424. {
  425. case 0:
  426. pRdi->str = pNode->GetConName( );
  427. break;
  428. case 1:
  429. pRdi->str = pNode->GetTTName( );
  430. break;
  431. case 2:
  432. pRdi->str = pNode->GetTypeName( );
  433. break;
  434. case 3:
  435. pRdi->str = pNode->GetComment( );
  436. break;
  437. }
  438. }
  439. }
  440. else if( pItem->GetNodeType( ) == RSETTINGS_NODE )
  441. {
  442. CSettingNode *pNode = ( CSettingNode *)pRdi->lParam;
  443. if( pRdi->mask & RDI_STR )
  444. {
  445. switch( pRdi->nCol )
  446. {
  447. case 0:
  448. pRdi->str = pNode->GetAttributeName( );
  449. break;
  450. case 1:
  451. if( pNode->GetObjectId( ) >= CUSTOM_EXTENSION )
  452. {
  453. DWORD dwStatus;
  454. pNode->SetAttributeValue( 0 , &dwStatus );
  455. }
  456. pRdi->str = pNode->GetCachedValue( );
  457. break;
  458. }
  459. }
  460. }
  461. }
  462. }
  463. return S_OK;
  464. }
  465. //--------------------------------------------------------------------------
  466. // Returns S_OK if they are similar S_FALSE otherwise
  467. //--------------------------------------------------------------------------
  468. STDMETHODIMP CComp::CompareObjects( LPDATAOBJECT , LPDATAOBJECT )
  469. {
  470. return S_OK;
  471. }
  472. //--------------------------------------------------------------------------
  473. //This has been added for when the user selects the Refresh menu item. We want
  474. //to rebuild the result node list because it can change thru an external script.
  475. //We're safe in doing this because Refresh can only be called when the focus
  476. //is not on a result node. If it can be, there's a danger of pointer corruption
  477. //in MMC, so we have to call InsertItemsinResultPane which is safer but not
  478. //as complete a refresh operation.
  479. HRESULT CComp::InsertAndBuildItemsinResultPane( )
  480. {
  481. HRESULT hr;
  482. if( m_pCompdata == NULL )
  483. return E_UNEXPECTED;
  484. //This removes the node information from the data in MMC
  485. if( FAILED( hr = m_pResultData->DeleteAllRsltItems( ) ) )
  486. return hr;
  487. if( FAILED( m_pCompdata->UpdateAllResultNodes( ) ) )
  488. {
  489. ODS( L"InsertItemsinResultPane - UpdateAllResultNodes failed!!\n" ) ;
  490. return FALSE;
  491. }
  492. //This puts the data for the nodes into m_pCompdata and also sends that same information to MMC
  493. if( FAILED( hr = m_pCompdata->InsertFolderItems( m_pResultData ) ) )
  494. return hr;
  495. return hr;
  496. }
  497. HRESULT CComp::InsertItemsinResultPane( )
  498. {
  499. HRESULT hr;
  500. if( m_pCompdata == NULL )
  501. return E_UNEXPECTED;
  502. //This removes the node information from the data in MMC
  503. if( FAILED( hr = m_pResultData->DeleteAllRsltItems( ) ) )
  504. return hr;
  505. //This is no longer being called because it's dangerous to modify all the result node pointers
  506. //during execution since there's a chance they'll get out of sync with MMC's result node
  507. //pointer list. This wasn't happening before because this is only called during an OnRefresh
  508. //operation, which could only be called when items in the left pane were selected. Now, however,
  509. //OnRefresh is called when switching between windows (bug 483485 - it has to be for MMC to get
  510. //the current window's pointer list), so it's possible for a result node to have the focus,
  511. //in which case the pointers don't get updated correctly and everything falls apart. When a
  512. //refresh operation is triggered by the menu item, the focus has to be in the left pane so
  513. //another method is used that includes this call to UpdateAllResultNodes
  514. /*if( FAILED( m_pCompdata->UpdateAllResultNodes( ) ) )
  515. {
  516. ODS( L"InsertItemsinResultPane - UpdateAllResultNodes failed!!\n" ) ;
  517. return FALSE;
  518. }*/
  519. //This puts the data for the nodes into m_pCompdata and also sends that same information to MMC
  520. if( FAILED( hr = m_pCompdata->InsertFolderItems( m_pResultData ) ) )
  521. return hr;
  522. return hr;
  523. }
  524. //--------------------------------------------------------------------------
  525. HRESULT CComp::AddSettingsinResultPane( )
  526. {
  527. HRESULT hr;
  528. if( m_pCompdata == NULL )
  529. return E_UNEXPECTED;
  530. //This removes the node information from the data in MMC
  531. if( FAILED( hr = m_pResultData->DeleteAllRsltItems( ) ) )
  532. return hr;
  533. if( FAILED( hr = m_pCompdata->InsertSettingItems( m_pResultData ) ) )
  534. return hr;
  535. return hr;
  536. }
  537. //--------------------------------------------------------------------------
  538. HRESULT CComp::OnSelect( LPDATAOBJECT pdo , BOOL bScope , BOOL bSelected )
  539. {
  540. CBaseNode *pNode = static_cast< CBaseNode * >( pdo );
  541. if( pNode == NULL )
  542. {
  543. return S_FALSE;
  544. }
  545. if( m_pConsoleVerb == NULL )
  546. {
  547. return E_UNEXPECTED;
  548. }
  549. // Item is being deselected and we're not interested currently
  550. if( !bSelected )
  551. {
  552. return S_OK;
  553. }
  554. // pNode == NULL if the folder item is being viewed in the result pane
  555. // settings node is ignored for this release
  556. if( bScope && pNode->GetNodeType( ) == MAIN_NODE )
  557. {
  558. m_pConsoleVerb->SetVerbState( MMC_VERB_REFRESH , ENABLED , TRUE );
  559. m_pConsoleVerb->SetDefaultVerb( MMC_VERB_OPEN );
  560. }
  561. else if( pNode->GetNodeType() == SETTINGS_NODE )
  562. {
  563. m_pConsoleVerb->SetVerbState( MMC_VERB_REFRESH , ENABLED , TRUE );
  564. }
  565. else if( pNode->GetNodeType() == RESULT_NODE )
  566. {
  567. m_pConsoleVerb->SetVerbState( MMC_VERB_DELETE , ENABLED , TRUE );
  568. //m_pConsoleVerb->SetVerbState( MMC_VERB_REFRESH , ENABLED , TRUE );
  569. m_pConsoleVerb->SetVerbState( MMC_VERB_PROPERTIES , ENABLED , TRUE );
  570. m_pConsoleVerb->SetDefaultVerb( MMC_VERB_PROPERTIES );
  571. }
  572. return S_OK;
  573. }
  574. //--------------------------------------------------------------------------
  575. STDMETHODIMP CComp::AddMenuItems( LPDATAOBJECT pdo , LPCONTEXTMENUCALLBACK pcmc , PLONG pl )
  576. {
  577. // CONTEXTMENUITEM cmi;
  578. if( pdo == NULL || pcmc == NULL )
  579. {
  580. return E_UNEXPECTED;
  581. }
  582. // do not allow scope node types
  583. if( m_pCompdata->IsConnectionFolder( pdo ) || m_pCompdata->IsSettingsFolder( pdo ) )
  584. {
  585. return S_FALSE;
  586. }
  587. CBaseNode *pNode = NULL;
  588. pNode = static_cast< CBaseNode * >( pdo );
  589. if( pNode == NULL )
  590. {
  591. return S_FALSE;
  592. }
  593. // hey root node has no menu items to insert.
  594. if( pNode->GetNodeType() == 0 )
  595. {
  596. return S_FALSE;
  597. }
  598. if( pNode->AddMenuItems( pcmc , pl ) )
  599. {
  600. return S_OK;
  601. }
  602. return E_FAIL;
  603. }
  604. //--------------------------------------------------------------------------
  605. // Toggles connection
  606. //--------------------------------------------------------------------------
  607. STDMETHODIMP CComp::Command( LONG lCmd , LPDATAOBJECT pdo )
  608. {
  609. TCHAR buf[ 512 ];
  610. TCHAR tchmsg[ 256 ];
  611. HRESULT hr;
  612. if( pdo == NULL )
  613. {
  614. return E_UNEXPECTED;
  615. }
  616. HWND hMain;
  617. if( FAILED( m_pConsole->GetMainWindow( &hMain ) ) )
  618. {
  619. hMain = NULL;
  620. }
  621. CResultNode *pNode = NULL;
  622. CSettingNode *pSetNode = NULL;
  623. if( pdo == NULL )
  624. {
  625. return S_FALSE;
  626. }
  627. if( ( ( CBaseNode * )pdo )->GetNodeType( ) == RSETTINGS_NODE )
  628. {
  629. pSetNode = ( CSettingNode * )pdo;
  630. BOOL bVal;
  631. DWORD dwStatus = 0;
  632. switch( lCmd )
  633. {
  634. case IDM_SETTINGS_PROPERTIES:
  635. OnDblClk( pdo );
  636. break;
  637. case IDM_SETTINGS_DELTEMPDIRSONEXIT:
  638. case IDM_SETTINGS_USETMPDIR:
  639. case IDM_SETTINGS_ADP:
  640. case IDM_SETTINGS_SS:
  641. {
  642. bVal = ( BOOL )pSetNode->xx_GetValue( );
  643. HCURSOR hCursor = SetCursor( LoadCursor( NULL , MAKEINTRESOURCE( IDC_WAIT ) ) );
  644. hr = pSetNode->SetAttributeValue( !bVal , &dwStatus );
  645. if( FAILED( hr ) )
  646. {
  647. SnodeErrorHandler( hMain , pSetNode->GetObjectId( ) , dwStatus );
  648. }
  649. //
  650. // We might want to move this code into OnRefresh() but for now, this is fix for
  651. // not updating attribute value and don't want to cause other regression
  652. //
  653. HRESULT hr;
  654. HRESULTITEM itemID;
  655. hr = m_pResultData->FindItemByLParam( (LPARAM) pdo, &itemID );
  656. if( SUCCEEDED(hr) )
  657. {
  658. m_pResultData->UpdateItem( itemID );
  659. }
  660. SetCursor( hCursor );
  661. }
  662. break;
  663. default:
  664. if( pSetNode->GetObjectId() >= CUSTOM_EXTENSION )
  665. {
  666. IExtendServerSettings *pEss = reinterpret_cast< IExtendServerSettings * >( pSetNode->GetInterface() );
  667. if( pEss != NULL )
  668. {
  669. pEss->ExecMenuCmd( lCmd , hMain , &dwStatus );
  670. // this forces the ui to be updated.
  671. if( dwStatus == UPDATE_TERMSRV || dwStatus == UPDATE_TERMSRV_SESSDIR )
  672. {
  673. ICfgComp *pCfgcomp = NULL;
  674. m_pCompdata->GetServer( &pCfgcomp );
  675. if( pCfgcomp != NULL )
  676. {
  677. ODS( L"TSCC!ExecMenuCmd forcing termsrv update\n" );
  678. if( dwStatus == UPDATE_TERMSRV_SESSDIR )
  679. {
  680. HCURSOR hCursor = SetCursor( LoadCursor( NULL ,
  681. MAKEINTRESOURCE( IDC_WAIT ) ) );
  682. if( FAILED( pCfgcomp->UpdateSessionDirectory( &dwStatus ) ) )
  683. {
  684. ReportStatusError( hMain , dwStatus );
  685. }
  686. HRESULTITEM itemID;
  687. hr = m_pResultData->FindItemByLParam( (LPARAM) pdo, &itemID );
  688. if( SUCCEEDED(hr) )
  689. {
  690. m_pResultData->UpdateItem( itemID );
  691. }
  692. SetCursor(hCursor);
  693. }
  694. else
  695. {
  696. pCfgcomp->ForceUpdate( );
  697. }
  698. pCfgcomp->Release();
  699. }
  700. }
  701. pSetNode->SetAttributeValue( 0 , &dwStatus );
  702. }
  703. }
  704. }
  705. }
  706. else if( ( ( CBaseNode * )pdo )->GetNodeType( ) == RESULT_NODE )
  707. {
  708. pNode = ( CResultNode * )pdo;
  709. if( lCmd == IDM_ENABLE_CONNECTION )
  710. {
  711. if( pNode->m_bEditMode )
  712. {
  713. xxxErrMessage( hMain , IDS_ERR_INEDITMODE , IDS_WARN_TITLE , MB_OK | MB_ICONWARNING );
  714. return S_FALSE;
  715. }
  716. ICfgComp *pCfgcomp;
  717. if( pNode->GetServer( &pCfgcomp ) != 0 )
  718. {
  719. WS *pWs;
  720. LONG lSz;
  721. if( SUCCEEDED( pCfgcomp->GetWSInfo( pNode->GetConName( ) , &lSz , &pWs ) ) )
  722. {
  723. BOOL bProceed = TRUE;
  724. pWs->fEnableWinstation = !pNode->GetConnectionState( );
  725. if( pWs->fEnableWinstation == 0 )
  726. {
  727. LONG lCount;
  728. // check to see if anyone is connected
  729. pCfgcomp->QueryLoggedOnCount( pNode->GetConName( ) , &lCount );
  730. if( lCount > 0 )
  731. {
  732. LoadString( _Module.GetResourceInstance( ) , IDS_DISABLELIVECONNECTION , tchmsg , SIZE_OF_BUFFER( tchmsg ) );
  733. }
  734. else
  735. {
  736. LoadString( _Module.GetResourceInstance( ) , IDS_DISABLECONNECTION , tchmsg , SIZE_OF_BUFFER( tchmsg ) );
  737. }
  738. wsprintf( buf , tchmsg , pNode->GetConName( ) );
  739. LoadString( _Module.GetResourceInstance( ) , IDS_WARN_TITLE , tchmsg , SIZE_OF_BUFFER( tchmsg ) );
  740. if( MessageBox( hMain , buf , tchmsg , MB_ICONWARNING | MB_YESNO ) == IDNO )
  741. {
  742. bProceed = FALSE;
  743. }
  744. }
  745. if( bProceed )
  746. {
  747. /*pNode->EnableConnection( pWs->fEnableWinstation );
  748. pNode->SetImageIdx( ( pWs->fEnableWinstation ? 1 : 2 ) );
  749. pCfgcomp->UpDateWS( pWs , UPDATE_ENABLEWINSTATION );
  750. m_pConsole->UpdateAllViews( ( LPDATAOBJECT )pNode , 0 , 0 );
  751. */
  752. DWORD dwStatus;
  753. if( FAILED( hr = pCfgcomp->UpDateWS( pWs , UPDATE_ENABLEWINSTATION , &dwStatus, TRUE ) ) )
  754. {
  755. if( hr == E_ACCESSDENIED )
  756. {
  757. TscAccessDeniedMsg( hMain );
  758. }
  759. else
  760. {
  761. TscGeneralErrMsg( hMain );
  762. }
  763. }
  764. else
  765. {
  766. pNode->EnableConnection( pWs->fEnableWinstation );
  767. pNode->SetImageIdx( ( pWs->fEnableWinstation ? 1 : 2 ) );
  768. m_pConsole->UpdateAllViews( ( LPDATAOBJECT )pNode , 0 , 0 );
  769. }
  770. }
  771. if(pWs->fEnableWinstation && pWs->PdClass == SdAsync)
  772. {
  773. ASYNCCONFIGW AsyncConfig;
  774. HRESULT hResult = pCfgcomp->GetAsyncConfig( pWs->Name , WsName , &AsyncConfig );
  775. if( SUCCEEDED( hResult ) )
  776. {
  777. if( AsyncConfig.ModemName[0] )
  778. {
  779. LoadString( _Module.GetResourceInstance( ) , IDS_REBOOT_REQD , buf , SIZE_OF_BUFFER( buf ) );
  780. LoadString( _Module.GetResourceInstance( ) , IDS_WARN_TITLE , tchmsg , SIZE_OF_BUFFER( tchmsg ) );
  781. MessageBox( hMain , buf , tchmsg , MB_ICONWARNING | MB_OK );
  782. }
  783. }
  784. }
  785. CoTaskMemFree( pWs );
  786. }
  787. pCfgcomp->Release( );
  788. }
  789. }
  790. else if( lCmd == IDM_RENAME_CONNECTION )
  791. {
  792. if( pNode->m_bEditMode )
  793. {
  794. xxxErrMessage( hMain , IDS_ERR_INEDITMODE , IDS_WARN_TITLE , MB_OK | MB_ICONWARNING );
  795. return S_FALSE;
  796. }
  797. ::DialogBoxParam( _Module.GetModuleInstance( ) , MAKEINTRESOURCE( IDD_RENAME ) , hMain , RenameDlgProc , ( LPARAM )pNode );
  798. }
  799. }
  800. return S_OK;
  801. }
  802. //--------------------------------------------------------------------------
  803. STDMETHODIMP CComp::CreatePropertyPages( LPPROPERTYSHEETCALLBACK psc , LONG_PTR Handle , LPDATAOBJECT pdo )
  804. {
  805. HRESULT hr = E_OUTOFMEMORY;
  806. if( psc == NULL )
  807. {
  808. return E_UNEXPECTED;
  809. }
  810. CPropsheet *pPropsheet = new CPropsheet( );
  811. if( pPropsheet != NULL )
  812. {
  813. HWND hMain;
  814. if( FAILED( m_pConsole->GetMainWindow( &hMain ) ) )
  815. {
  816. hMain = NULL;
  817. }
  818. if( FAILED( ( hr = pPropsheet->InitDialogs( hMain , psc , dynamic_cast< CResultNode *>( pdo ) , Handle ) ) ) )
  819. {
  820. delete pPropsheet;
  821. }
  822. }
  823. return hr;
  824. }
  825. //--------------------------------------------------------------------------
  826. STDMETHODIMP CComp::QueryPagesFor( LPDATAOBJECT pdo )
  827. {
  828. if( dynamic_cast< CResultNode *>( pdo ) == NULL )
  829. {
  830. return E_INVALIDARG;
  831. }
  832. return S_OK;
  833. }
  834. //--------------------------------------------------------------------------
  835. BOOL CComp::OnDelete( LPDATAOBJECT pDo )
  836. {
  837. CResultNode *pNode = dynamic_cast< CResultNode *>( pDo );
  838. if( pNode == NULL )
  839. {
  840. ODS( L"TSCC: OnDelete, node == NULL\n");
  841. return FALSE;
  842. }
  843. if( pNode->m_bEditMode )
  844. {
  845. HWND hMain;
  846. if( FAILED( m_pConsole->GetMainWindow( &hMain ) ) )
  847. {
  848. hMain = NULL;
  849. }
  850. xxxErrMessage( hMain , IDS_ERR_INEDITMODE , IDS_WARN_TITLE , MB_OK | MB_ICONWARNING );
  851. return FALSE;
  852. }
  853. return m_pCompdata->OnDeleteItem( pDo );
  854. }
  855. //--------------------------------------------------------------------------
  856. // CResultNode passed in on init
  857. //--------------------------------------------------------------------------
  858. INT_PTR CALLBACK RenameDlgProc( HWND hDlg , UINT msg , WPARAM wp , LPARAM lp )
  859. {
  860. CResultNode *pNode;
  861. TCHAR tchNewName[ 60 ];
  862. // HWND h;
  863. switch( msg )
  864. {
  865. case WM_INITDIALOG :
  866. pNode = ( CResultNode *)lp;
  867. ASSERT( pNode != NULL );
  868. // ok to store null -- it's initializing DWLP_USER area
  869. SetWindowLongPtr( hDlg , DWLP_USER , ( LONG_PTR )pNode );
  870. // Insert name
  871. ICfgComp *pCfgcomp;
  872. if( pNode == NULL )
  873. {
  874. break;
  875. }
  876. if( pNode->GetServer( &pCfgcomp ) == 0 )
  877. {
  878. ASSERT( 0 );
  879. break;
  880. }
  881. SetWindowText( GetDlgItem( hDlg , IDC_STATIC_CURRENT_NAME ) , pNode->GetConName( ) );
  882. pCfgcomp->Release( );
  883. SetFocus( GetDlgItem( hDlg , IDC_EDIT_NEWNAME ) );
  884. SendMessage( GetDlgItem( hDlg , IDC_EDIT_NEWNAME ) , EM_SETLIMITTEXT , ( WPARAM )( WINSTATIONNAME_LENGTH - WINSTATION_NAME_TRUNCATE_BY ) , 0 );
  885. break;
  886. case WM_COMMAND:
  887. if( LOWORD( wp ) == IDOK )
  888. {
  889. pNode = ( CResultNode *)GetWindowLongPtr( hDlg , DWLP_USER );
  890. if( pNode == NULL )
  891. {
  892. break;
  893. }
  894. DWORD dwErr = 0;
  895. if( GetWindowText( GetDlgItem( hDlg , IDC_EDIT_NEWNAME ) , tchNewName , SIZE_OF_BUFFER( tchNewName ) ) == 0 ||
  896. !IsValidConnectionName( tchNewName , &dwErr ) )
  897. {
  898. if( dwErr == ERROR_INVALID_FIRSTCHARACTER )
  899. {
  900. ErrMessage( hDlg , IDS_ERR_INVALIDFIRSTCHAR );
  901. }
  902. else
  903. {
  904. ErrMessage( hDlg , IDS_ERR_INVALIDCHARS );
  905. }
  906. SetFocus( GetDlgItem( hDlg , IDC_EDIT_NEWNAME ) );
  907. SendMessage( GetDlgItem( hDlg , IDC_EDIT_NEWNAME ) , EM_SETSEL , ( WPARAM )0 , ( LPARAM )-1 );
  908. return 0;
  909. }
  910. // verify the name is unique
  911. ICfgComp *pCfgcomp;
  912. if( pNode->GetServer( &pCfgcomp ) == 0 )
  913. {
  914. ODS( L"GetServer failed in RenameDlgProc\n" );
  915. break;
  916. }
  917. do
  918. {
  919. BOOL bUnique = FALSE;
  920. if( FAILED( pCfgcomp->IsWSNameUnique( ( PWINSTATIONNAMEW )tchNewName , &bUnique ) ) )
  921. {
  922. break;
  923. }
  924. if( !bUnique )
  925. {
  926. ErrMessage( hDlg , IDS_ERR_WINNAME );
  927. pCfgcomp->Release( );
  928. SetFocus( GetDlgItem( hDlg , IDC_EDIT_NEWNAME ) );
  929. SendMessage( GetDlgItem( hDlg , IDC_EDIT_NEWNAME ) , EM_SETSEL , ( WPARAM )0 , ( LPARAM )-1 );
  930. return 0;
  931. }
  932. HRESULT hr;
  933. LONG lCount;
  934. TCHAR tchWrnBuf[ 256 ];
  935. TCHAR tchOutput[ 512 ];
  936. // check to see if anyone is connected
  937. pCfgcomp->QueryLoggedOnCount( pNode->GetConName( ) , &lCount );
  938. if( lCount > 0 )
  939. {
  940. if( lCount == 1 )
  941. {
  942. LoadString( _Module.GetResourceInstance() , IDS_RENAME_WRN_SINGLE , tchWrnBuf , SIZE_OF_BUFFER( tchWrnBuf ) );
  943. }
  944. else
  945. {
  946. LoadString( _Module.GetResourceInstance() , IDS_RENAME_WRN_PL , tchWrnBuf , SIZE_OF_BUFFER( tchWrnBuf ) );
  947. }
  948. wsprintf( tchOutput , tchWrnBuf , pNode->GetConName( ) );
  949. LoadString( _Module.GetResourceInstance( ) , IDS_WARN_TITLE , tchWrnBuf , SIZE_OF_BUFFER( tchWrnBuf ) );
  950. if( MessageBox( hDlg , tchOutput , tchWrnBuf , MB_ICONWARNING | MB_YESNO ) == IDNO )
  951. {
  952. break;
  953. }
  954. }
  955. if( FAILED( hr = pCfgcomp->RenameWinstation( ( PWINSTATIONNAMEW )pNode->GetConName( ) , ( PWINSTATIONNAMEW )tchNewName ) ) )
  956. {
  957. ODS( L"TSCC: RenameWinstation failed\n" );
  958. if( hr == E_ACCESSDENIED )
  959. {
  960. TscAccessDeniedMsg( hDlg );
  961. }
  962. else
  963. {
  964. TscGeneralErrMsg( hDlg );
  965. }
  966. break;
  967. }
  968. /*
  969. LONG lCount;
  970. TCHAR tchWrnBuf[ 256 ];
  971. TCHAR tchOutput[ 512 ];
  972. // check to see if anyone is connected
  973. pCfgcomp->QueryLoggedOnCount( pNode->GetConName( ) , &lCount );
  974. if( lCount > 0 )
  975. {
  976. if( lCount == 1 )
  977. {
  978. LoadString( _Module.GetResourceInstance() , IDS_RENAME_WRN_SINGLE , tchWrnBuf , SIZE_OF_BUFFER( tchWrnBuf ) );
  979. }
  980. else
  981. {
  982. LoadString( _Module.GetResourceInstance() , IDS_RENAME_WRN_PL , tchWrnBuf , SIZE_OF_BUFFER( tchWrnBuf ) );
  983. }
  984. wsprintf( tchOutput , tchWrnBuf , pNode->GetConName( ) );
  985. LoadString( _Module.GetResourceInstance( ) , IDS_WARN_TITLE , tchWrnBuf , SIZE_OF_BUFFER( tchWrnBuf ) );
  986. MessageBox( hDlg , tchOutput , tchWrnBuf , MB_OK | MB_ICONWARNING );
  987. }
  988. */
  989. WS *pWs;
  990. LONG lSz;
  991. if( SUCCEEDED( pCfgcomp->GetWSInfo(tchNewName , &lSz , &pWs ) ) )
  992. {
  993. if(pWs->fEnableWinstation && pWs->PdClass == SdAsync)
  994. {
  995. ASYNCCONFIGW AsyncConfig;
  996. HRESULT hResult = pCfgcomp->GetAsyncConfig( pWs->Name , WsName , &AsyncConfig );
  997. if( SUCCEEDED( hResult ) )
  998. {
  999. if( AsyncConfig.ModemName[0] )
  1000. {
  1001. LoadString( _Module.GetResourceInstance( ) , IDS_REBOOT_REQD , tchOutput , SIZE_OF_BUFFER( tchOutput ) );
  1002. LoadString( _Module.GetResourceInstance( ) , IDS_WARN_TITLE , tchWrnBuf , SIZE_OF_BUFFER( tchWrnBuf ) );
  1003. MessageBox( hDlg , tchOutput , tchWrnBuf , MB_ICONWARNING | MB_OK );
  1004. }
  1005. }
  1006. }
  1007. CoTaskMemFree( pWs );
  1008. }
  1009. pNode->SetConName( tchNewName , SIZE_OF_BUFFER( tchNewName ) );
  1010. }while( 0 );
  1011. pCfgcomp->Release( );
  1012. EndDialog( hDlg , 0 );
  1013. }
  1014. else if( LOWORD( wp ) == IDCANCEL )
  1015. {
  1016. EndDialog( hDlg , 0 );
  1017. }
  1018. break;
  1019. }
  1020. return 0;
  1021. }
  1022. //--------------------------------------------------------------------------
  1023. BOOL IsValidConnectionName( LPTSTR szConName , PDWORD pdwErr )
  1024. {
  1025. TCHAR tchInvalidChars[ 80 ];
  1026. tchInvalidChars[0] = 0;
  1027. if( szConName == NULL || pdwErr == NULL )
  1028. {
  1029. return FALSE;
  1030. }
  1031. if( _istdigit( szConName[ 0 ] ) )
  1032. {
  1033. *pdwErr = ERROR_INVALID_FIRSTCHARACTER;
  1034. return FALSE;
  1035. }
  1036. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance() , IDS_INVALID_CHARS , tchInvalidChars , SIZE_OF_BUFFER( tchInvalidChars ) ) );
  1037. int nLen = lstrlen( tchInvalidChars );
  1038. while( *szConName )
  1039. {
  1040. for( int idx = 0 ; idx < nLen ; idx++ )
  1041. {
  1042. if( *szConName == tchInvalidChars[ idx ] )
  1043. {
  1044. *pdwErr = ERROR_ILLEGAL_CHARACTER;
  1045. return FALSE;
  1046. }
  1047. }
  1048. szConName++;
  1049. }
  1050. *pdwErr = ERROR_SUCCESS;
  1051. return TRUE;
  1052. }
  1053. //----------------------------------------------------------------------
  1054. BOOL CComp::OnHelp( LPDATAOBJECT pDo )
  1055. {
  1056. TCHAR tchTopic[ 80 ];
  1057. HRESULT hr = E_FAIL;
  1058. if( pDo == NULL || m_pDisplayHelp == NULL )
  1059. {
  1060. return hr;
  1061. }
  1062. INT_PTR nNodeType = ( ( CBaseNode * )pDo )->GetNodeType();
  1063. if( nNodeType == RESULT_NODE || nNodeType == MAIN_NODE || nNodeType == 0 )
  1064. {
  1065. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance() , IDS_TSCCHELPTOPIC , tchTopic , SIZE_OF_BUFFER( tchTopic ) ) );
  1066. hr = m_pDisplayHelp->ShowTopic( tchTopic );
  1067. }
  1068. else if( nNodeType == SETTINGS_NODE || nNodeType == RSETTINGS_NODE )
  1069. {
  1070. if( nNodeType == SETTINGS_NODE )
  1071. {
  1072. IExtendServerSettings *pEss = NULL;
  1073. INT iRet = -1;
  1074. CSettingNode *pNode = dynamic_cast< CSettingNode *>( pDo );
  1075. if( pNode != NULL )
  1076. {
  1077. if( pNode->GetObjectId( ) >= CUSTOM_EXTENSION )
  1078. {
  1079. pEss = reinterpret_cast< IExtendServerSettings * >( pNode->GetInterface( ) );
  1080. if( pEss != NULL )
  1081. {
  1082. pEss->OnHelp( &iRet );
  1083. if( iRet == 0 )
  1084. {
  1085. return TRUE;
  1086. }
  1087. }
  1088. }
  1089. }
  1090. }
  1091. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance() , IDS_SETTINGSHELP , tchTopic , SIZE_OF_BUFFER( tchTopic ) ) );
  1092. hr = m_pDisplayHelp->ShowTopic( tchTopic );
  1093. }
  1094. return ( SUCCEEDED( hr ) ? TRUE : FALSE );
  1095. }
  1096. //----------------------------------------------------------------------
  1097. BOOL CComp::OnDblClk( LPDATAOBJECT pDo )
  1098. {
  1099. CSettingNode *pNode = dynamic_cast< CSettingNode *>( pDo );
  1100. if( pNode == NULL )
  1101. {
  1102. // we're only concerned about Setting nodes
  1103. return FALSE;
  1104. }
  1105. HWND hMain;
  1106. if( FAILED( m_pConsole->GetMainWindow( &hMain ) ) )
  1107. {
  1108. hMain = NULL;
  1109. }
  1110. INT nObjectId = pNode->GetObjectId( );
  1111. switch( nObjectId )
  1112. {
  1113. /*
  1114. case 0:
  1115. ::DialogBoxParam( _Module.GetModuleInstance( ) , MAKEINTRESOURCE( IDD_CACHED_SESSIONS ) , hMain , CachedSessionsDlgProc , ( LPARAM )pNode );
  1116. break;*/
  1117. case DELETED_DIRS_ONEXIT:
  1118. ::DialogBoxParam( _Module.GetModuleInstance( ) , MAKEINTRESOURCE( IDD_YESNODIALOG ) , hMain , DeleteTempDirsDlgProc , ( LPARAM )pNode );
  1119. break;
  1120. case PERSESSION_TEMPDIR:
  1121. ::DialogBoxParam( _Module.GetModuleInstance( ) , MAKEINTRESOURCE( IDD_DIALOG_PERSESSION ) , hMain , UsePerSessionTempDirsDlgProc , ( LPARAM )pNode );
  1122. break;
  1123. /*
  1124. case DEF_CONSECURITY:
  1125. ::DialogBoxParam( _Module.GetModuleInstance( ) , MAKEINTRESOURCE( IDD_DEFCONSEC ) , hMain , DefConSecurityDlgProc , ( LPARAM )pNode );
  1126. break;
  1127. */
  1128. case LICENSING:
  1129. ::DialogBoxParam( _Module.GetModuleInstance( ) , MAKEINTRESOURCE( IDD_LICENSING ) , hMain , LicensingDlgProc , ( LPARAM )pNode );
  1130. break;
  1131. case ACTIVE_DESK:
  1132. ::DialogBoxParam( _Module.GetModuleInstance( ) , MAKEINTRESOURCE( IDD_ADP_DIALOG ) , hMain , ConfigActiveDesktop , ( LPARAM )pNode );
  1133. break;
  1134. case USERSECURITY:
  1135. // error if we're trying to modify property in remote admin mode
  1136. if( !g_bAppSrvMode )
  1137. {
  1138. xxxErrMessage( hMain , IDS_REMOTEADMIN_ONLY , IDS_WARN_TITLE , MB_OK | MB_ICONINFORMATION );
  1139. break;
  1140. }
  1141. ::DialogBoxParam( _Module.GetModuleInstance( ) , MAKEINTRESOURCE( IDD_PROPPAGE_TERMINAL_SERVER_PERM ) , hMain , UserPermCompat , ( LPARAM )pNode );
  1142. break;
  1143. case SINGLE_SESSION:
  1144. ::DialogBoxParam( _Module.GetModuleInstance( ) , MAKEINTRESOURCE( IDD_SINGLE_SESSION) , hMain , ConfigSingleSession , ( LPARAM )pNode );
  1145. break;
  1146. default:
  1147. if( nObjectId >= CUSTOM_EXTENSION )
  1148. {
  1149. IExtendServerSettings *pEss = reinterpret_cast< IExtendServerSettings * >( pNode->GetInterface() );
  1150. if( pEss != NULL )
  1151. {
  1152. DWORD dwStatus;
  1153. pEss->InvokeUI( hMain , &dwStatus );
  1154. if( dwStatus == UPDATE_TERMSRV || dwStatus == UPDATE_TERMSRV_SESSDIR )
  1155. {
  1156. ICfgComp *pCfgcomp = NULL;
  1157. m_pCompdata->GetServer( &pCfgcomp );
  1158. if( pCfgcomp != NULL )
  1159. {
  1160. ODS( L"TSCC!Comp OnDblClk forcing termsrv update\n" );
  1161. if( dwStatus == UPDATE_TERMSRV_SESSDIR )
  1162. {
  1163. HCURSOR hCursor = SetCursor( LoadCursor( NULL ,
  1164. MAKEINTRESOURCE( IDC_WAIT ) ) );
  1165. if( FAILED( pCfgcomp->UpdateSessionDirectory( &dwStatus ) ) )
  1166. {
  1167. ReportStatusError( hMain , dwStatus );
  1168. }
  1169. SetCursor(hCursor);
  1170. }
  1171. else
  1172. {
  1173. pCfgcomp->ForceUpdate( );
  1174. }
  1175. pCfgcomp->Release();
  1176. }
  1177. }
  1178. }
  1179. }
  1180. }
  1181. return TRUE;
  1182. }
  1183. /*
  1184. //----------------------------------------------------------------------
  1185. HRESULT CComp::SetColumnWidth( int nCol )
  1186. {
  1187. HWND hMain;
  1188. int nCurColLen;
  1189. CResultNode *pNode;
  1190. do
  1191. {
  1192. if( FAILED( m_pHeaderCtrl->GetColumnWidth( nCol , &nCurColLen ) ) )
  1193. {
  1194. break;
  1195. }
  1196. if( FAILED( m_pConsole->GetMainWindow( &hMain ) ) )
  1197. {
  1198. break;
  1199. }
  1200. HDC hdc = GetDC( hMain );
  1201. SIZE sz;
  1202. int idx = 0;
  1203. TCHAR *psz;
  1204. while( ( pNode = *m_pCompdata->GetResultNode( idx ) ) != NULL )
  1205. {
  1206. switch( nCol )
  1207. {
  1208. case 0:
  1209. psz = pNode->GetConName( );
  1210. break;
  1211. case 1:
  1212. psz = pNode->GetTTName( );
  1213. break;
  1214. case 2:
  1215. psz = pNode->GetTypeName( );
  1216. break;
  1217. // comment is too big allow user to adjust size
  1218. }
  1219. GetTextExtentPoint32( hdc , psz , lstrlen( psz ) , &sz );
  1220. if( sz.cx > nCurColLen )
  1221. {
  1222. nCurColLen = sz.cx;
  1223. }
  1224. idx++;
  1225. }
  1226. m_pHeaderCtrl->SetColumnWidth( nCol , nCurColLen );
  1227. ReleaseDC( hMain , hdc );
  1228. } while( 0 );
  1229. return S_OK;
  1230. }
  1231. */
  1232. //----------------------------------------------------------------------
  1233. HRESULT CComp::SetColumnsForSettingsPane( )
  1234. {
  1235. HWND hParent;
  1236. SIZE sz = { 0 , 0 };
  1237. TCHAR tchBuffer[ 256 ];
  1238. INT nMaxLen;
  1239. if( FAILED( m_pConsole->GetMainWindow( &hParent ) ) )
  1240. {
  1241. hParent = NULL;
  1242. }
  1243. HDC hdc = GetDC( hParent );
  1244. if( hdc != NULL )
  1245. {
  1246. m_pCompdata->GetMaxTextLengthSetting( tchBuffer , &nMaxLen );
  1247. VERIFY_S( TRUE , GetTextExtentPoint32( hdc , tchBuffer , nMaxLen , &sz ) );
  1248. m_nSettingCol = sz.cx - 16 ; // remove icon width from column width
  1249. m_pCompdata->GetMaxTextLengthAttribute( tchBuffer , &nMaxLen );
  1250. VERIFY_S( TRUE , GetTextExtentPoint32( hdc , tchBuffer , nMaxLen , &sz ) );
  1251. m_nAttribCol = sz.cx;
  1252. ReleaseDC( hParent , hdc );
  1253. }
  1254. return S_OK;
  1255. }