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.

711 lines
19 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. /*******************************************************************************
  3. *
  4. * servervw.cpp
  5. *
  6. * implementation of the CServerView class
  7. *
  8. *
  9. *******************************************************************************/
  10. #include "stdafx.h"
  11. #include "resource.h"
  12. #include "servervw.h"
  13. #include "admindoc.h"
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. //////////////////////////
  20. // MESSAGE MAP: CServerView
  21. //
  22. IMPLEMENT_DYNCREATE(CServerView, CView)
  23. BEGIN_MESSAGE_MAP(CServerView, CView)
  24. //{{AFX_MSG_MAP(CServerView)
  25. ON_WM_SIZE()
  26. ON_WM_CREATE()
  27. //}}AFX_MSG_MAP
  28. ON_MESSAGE(WM_ADMIN_UPDATE_PROCESSES, OnAdminUpdateProcesses)
  29. ON_NOTIFY(TCN_SELCHANGE, IDC_SERVER_TABS, OnTabSelChange)
  30. ON_MESSAGE(WM_ADMIN_REMOVE_PROCESS, OnAdminRemoveProcess)
  31. ON_MESSAGE(WM_ADMIN_REDISPLAY_PROCESSES, OnAdminRedisplayProcesses)
  32. ON_MESSAGE(WM_ADMIN_UPDATE_SERVER_INFO, OnAdminUpdateServerInfo)
  33. ON_MESSAGE(WM_ADMIN_REDISPLAY_LICENSES, OnAdminRedisplayLicenses)
  34. ON_MESSAGE(WM_ADMIN_UPDATE_WINSTATIONS, OnAdminUpdateWinStations)
  35. ON_MESSAGE( WM_ADMIN_TABBED_VIEW , OnTabbed )
  36. ON_MESSAGE( WM_ADMIN_SHIFTTABBED_VIEW , OnShiftTabbed )
  37. ON_MESSAGE( WM_ADMIN_CTRLTABBED_VIEW , OnCtrlTabbed )
  38. ON_MESSAGE( WM_ADMIN_CTRLSHIFTTABBED_VIEW , OnCtrlShiftTabbed )
  39. ON_MESSAGE( WM_ADMIN_NEXTPANE_VIEW , OnNextPane )
  40. END_MESSAGE_MAP()
  41. PageDef CServerView::pages[NUMBER_OF_PAGES] = {
  42. { NULL, RUNTIME_CLASS( CUsersPage ), IDS_TAB_USERS, PAGE_USERS, NULL },
  43. { NULL, RUNTIME_CLASS( CServerWinStationsPage ), IDS_TAB_WINSTATIONS,PAGE_WINSTATIONS, NULL },
  44. { NULL, RUNTIME_CLASS( CServerProcessesPage ), IDS_TAB_PROCESSES, PAGE_PROCESSES, NULL },
  45. { NULL, RUNTIME_CLASS( CServerLicensesPage ), IDS_TAB_LICENSES, PAGE_LICENSES, PF_PICASSO_ONLY }
  46. // { NULL, RUNTIME_CLASS( CServerInfoPage ), IDS_TAB_INFORMATION,PAGE_INFO, NULL }
  47. };
  48. ///////////////////////
  49. // F'N: CServerView ctor
  50. //
  51. CServerView::CServerView()
  52. {
  53. m_pTabs = NULL;
  54. m_pTabFont = NULL;
  55. m_pServer = NULL;
  56. m_CurrPage = PAGE_USERS;
  57. } // end CServerView ctor
  58. ///////////////////////
  59. // F'N: CServerView dtor
  60. //
  61. CServerView::~CServerView()
  62. {
  63. if(m_pTabs) delete m_pTabs;
  64. if(m_pTabFont) delete m_pTabFont;
  65. } // end CServerView dtor
  66. #ifdef _DEBUG
  67. ///////////////////////////////
  68. // F'N: CServerView::AssertValid
  69. //
  70. void CServerView::AssertValid() const
  71. {
  72. CView::AssertValid();
  73. } // end CServerView::AssertValid
  74. ////////////////////////
  75. // F'N: CServerView::Dump
  76. //
  77. void CServerView::Dump(CDumpContext& dc) const
  78. {
  79. CView::Dump(dc);
  80. } // end CServerView::Dump
  81. #endif //_DEBUG
  82. ////////////////////////////
  83. // F'N: CServerView::OnCreate
  84. //
  85. int CServerView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  86. {
  87. if (CView::OnCreate(lpCreateStruct) == -1)
  88. return -1;
  89. return 0;
  90. } // end CServerView::OnCreate
  91. ///////////////////////////////////
  92. // F'N: CServerView::OnInitialUpdate
  93. //
  94. // - pointers to the pages of the sheet are obtained
  95. //
  96. void CServerView::OnInitialUpdate()
  97. {
  98. // create the CServerTabs
  99. m_pTabs = new CMyTabCtrl;
  100. if(!m_pTabs) return;
  101. m_pTabs->Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP, CRect(0,0,0,0), this, IDC_SERVER_TABS);
  102. m_pTabFont = new CFont;
  103. if(m_pTabFont) {
  104. m_pTabFont->CreateStockObject(DEFAULT_GUI_FONT);
  105. m_pTabs->SetFont(m_pTabFont, TRUE);
  106. }
  107. TCHAR szTemp[40];
  108. CString tabString;
  109. int index = 0;
  110. for(int i = 0; i < NUMBER_OF_PAGES; i++) {
  111. // If the page is shown under Picasso only and we're not running
  112. // under Picasso, skip to the next one
  113. if((pages[i].flags & PF_PICASSO_ONLY) && !((CWinAdminApp*)AfxGetApp())->IsPicasso()) continue;
  114. tabString.LoadString(pages[i].tabStringID);
  115. lstrcpyn(szTemp, tabString, sizeof(szTemp) / sizeof(TCHAR));
  116. AddTab(index, szTemp, i);
  117. pages[i].m_pPage = (CAdminPage*)pages[i].m_pRuntimeClass->CreateObject();
  118. pages[i].m_pPage->Create(NULL, NULL, WS_CHILD, CRect(0, 0, 0, 0), this, i, NULL);
  119. GetDocument()->AddView(pages[i].m_pPage);
  120. index++;
  121. }
  122. m_pTabs->SetCurSel(0);
  123. m_CurrPage = PAGE_USERS;
  124. ((CWinAdminDoc*)GetDocument())->SetCurrentPage(PAGE_USERS);
  125. OnChangePage(NULL, NULL);
  126. } // end CServerView::OnInitialUpdate
  127. //////////////////////////
  128. // F'N: CServerView::OnSize
  129. //
  130. // - size the pages to fill the entire view
  131. //
  132. void CServerView::OnSize(UINT nType, int cx, int cy)
  133. {
  134. RECT rect;
  135. GetClientRect(&rect);
  136. if(m_pTabs->GetSafeHwnd()) { // make sure the CServerTabs object is valid
  137. m_pTabs->MoveWindow(&rect, TRUE); // size the tabs
  138. // for the next part (sizing of pages), we might want to add a member var
  139. // that keeps track of which page/tab is current... this way we could
  140. // only actually do a redraw (MoveWindow second parm == TRUE) for the
  141. // guy who is currently visible--DJM
  142. // we want to size the pages, too
  143. m_pTabs->AdjustRect(FALSE, &rect);
  144. for(int i = 0; i < NUMBER_OF_PAGES; i++) {
  145. if(pages[i].m_pPage && pages[i].m_pPage->GetSafeHwnd())
  146. pages[i].m_pPage->MoveWindow(&rect, TRUE);
  147. }
  148. }
  149. } // end CServerView::OnSize
  150. //////////////////////////
  151. // F'N: CServerView::OnDraw
  152. //
  153. // - the CServerView and it's pages draw themselves, so there isn't anything
  154. // to do here...
  155. //
  156. void CServerView::OnDraw(CDC* pDC)
  157. {
  158. CDocument* pDoc = GetDocument();
  159. // TODO: add draw code here
  160. } // end CServerView::OnDraw
  161. /////////////////////////
  162. // F'N: CServerView::Reset
  163. //
  164. // - 'resets' the view by taking a pointer to a CServer object and filling in
  165. // the various property pages with info appropriate to that server
  166. //
  167. void CServerView::Reset(void *pServer)
  168. {
  169. ((CServer*)pServer)->ClearAllSelected();
  170. m_pServer = (CServer*)pServer;
  171. if(((CWinAdminApp*)AfxGetApp())->IsPicasso())
  172. {
  173. int PreviousTab = m_pTabs->GetCurSel();
  174. BOOLEAN bWinFrame = ((CServer*)pServer)->IsWinFrame();
  175. // Delete all the tabs
  176. m_pTabs->DeleteAllItems();
  177. // If this server isn't a WinFrame server, the current page might not be
  178. // applicable
  179. int CurrentPage = m_CurrPage;
  180. if(!bWinFrame && CurrentPage == PAGE_LICENSES)
  181. {
  182. CurrentPage = PAGE_INFO;
  183. }
  184. // create tabs only for pages we want to show for this server
  185. int index = 0;
  186. TCHAR szTemp[40];
  187. CString tabString;
  188. int CurrentTab = 0;
  189. for(int i = 0; i < NUMBER_OF_PAGES; i++)
  190. {
  191. if((pages[i].flags & PF_PICASSO_ONLY) && !bWinFrame)
  192. {
  193. continue;
  194. }
  195. tabString.LoadString(pages[i].tabStringID);
  196. lstrcpyn(szTemp, tabString, sizeof(szTemp) / sizeof(TCHAR));
  197. AddTab(index, szTemp, i);
  198. if(pages[i].page == CurrentPage)
  199. {
  200. CurrentTab = index;
  201. }
  202. index++;
  203. }
  204. m_pTabs->SetCurSel(CurrentTab);
  205. if(PreviousTab == CurrentTab && CurrentPage != m_CurrPage)
  206. OnChangePage(NULL, NULL);
  207. }
  208. ((CWinAdminDoc*)GetDocument())->SetCurrentPage(m_CurrPage);
  209. // Reset pages
  210. for(int i = 0; i < NUMBER_OF_PAGES; i++)
  211. {
  212. if(pages[i].m_pPage != NULL )
  213. {
  214. pages[i].m_pPage->Reset((CServer*)pServer);
  215. }
  216. }
  217. } // end CServerView::Reset
  218. //////////////////////////
  219. // F'N: CServerView::AddTab
  220. //
  221. void CServerView::AddTab(int index, TCHAR* text, ULONG pageindex)
  222. {
  223. TC_ITEM tc;
  224. tc.mask = TCIF_TEXT | TCIF_PARAM;
  225. tc.pszText = text;
  226. tc.lParam = pageindex;
  227. m_pTabs->InsertItem(index, &tc);
  228. } // end CServerView::AddTab
  229. ////////////////////////////////
  230. // F'N: CServerView::OnChangePage
  231. //
  232. // - changes to a new server page based on currently selected tab
  233. // - OnChangePage needs to force recalculation of scroll bars!!!--DJM
  234. //
  235. LRESULT CServerView::OnChangePage(WPARAM wParam, LPARAM lParam)
  236. {
  237. // find out which tab is now selected
  238. int tab = m_pTabs->GetCurSel();
  239. TC_ITEM tc;
  240. tc.mask = TCIF_PARAM;
  241. m_pTabs->GetItem(tab, &tc);
  242. int index = (int)tc.lParam;
  243. // hide the current page
  244. pages[m_CurrPage].m_pPage->ModifyStyle(WS_VISIBLE, WS_DISABLED);
  245. pages[m_CurrPage].m_pPage->ClearSelections();
  246. m_CurrPage = index;
  247. ((CWinAdminDoc*)GetDocument())->SetCurrentPage(m_CurrPage);
  248. // show the new page
  249. pages[index].m_pPage->ModifyStyle(WS_DISABLED, WS_VISIBLE);
  250. pages[index].m_pPage->ScrollToPosition(CPoint(0,0));
  251. pages[index].m_pPage->Invalidate();
  252. if(m_pServer) m_pServer->ClearAllSelected();
  253. return 0;
  254. } // end CServerView::OnChangeview
  255. void CServerView::OnTabSelChange(NMHDR* pNMHDR, LRESULT* pResult)
  256. {
  257. OnChangePage( 0 , 0 );
  258. *pResult = 0;
  259. } // end CServerView::OnTabSelChange
  260. LRESULT CServerView::OnAdminUpdateProcesses(WPARAM wParam, LPARAM lParam)
  261. {
  262. ((CServerProcessesPage*)pages[PAGE_PROCESSES].m_pPage)->UpdateProcesses();
  263. return 0;
  264. } // end CServerView::OnAdminUpdateProcesses
  265. LRESULT CServerView::OnAdminRedisplayProcesses(WPARAM wParam, LPARAM lParam)
  266. {
  267. ((CServerProcessesPage*)pages[PAGE_PROCESSES].m_pPage)->DisplayProcesses();
  268. return 0;
  269. } // end CServerView::OnAdminRedisplayProcesses
  270. LRESULT CServerView::OnAdminRemoveProcess(WPARAM wParam, LPARAM lParam)
  271. {
  272. ((CServerProcessesPage*)pages[PAGE_PROCESSES].m_pPage)->RemoveProcess((CProcess*)lParam);
  273. return 0;
  274. } // end CServerView::OnAdminRemoveProcess
  275. LRESULT CServerView::OnAdminUpdateWinStations(WPARAM wParam, LPARAM lParam)
  276. {
  277. ((CUsersPage*)pages[PAGE_USERS].m_pPage)->UpdateWinStations((CServer*)lParam);
  278. ((CServerWinStationsPage*)pages[PAGE_WINSTATIONS].m_pPage)->UpdateWinStations((CServer*)lParam);
  279. return 0;
  280. } // end CServerView::OnAdminUpdateWinStations
  281. LRESULT CServerView::OnAdminUpdateServerInfo(WPARAM wParam, LPARAM lParam)
  282. {
  283. /* ((CServerInfoPage*)pages[PAGE_INFO].m_pPage)->DisplayInfo(); */
  284. if(pages[PAGE_LICENSES].m_pPage)
  285. ((CServerLicensesPage*)pages[PAGE_LICENSES].m_pPage)->DisplayLicenseCounts();
  286. return 0;
  287. } // end CServerView::OnAdminUpdateServerInfo
  288. LRESULT CServerView::OnAdminRedisplayLicenses(WPARAM wParam, LPARAM lParam)
  289. {
  290. if(pages[PAGE_LICENSES].m_pPage)
  291. ((CServerLicensesPage*)pages[PAGE_LICENSES].m_pPage)->Reset((CServer*)lParam);
  292. return 0;
  293. } // end CServerView::OnAdminRedisplayLicenses
  294. LRESULT CServerView::OnTabbed( WPARAM wp , LPARAM lp )
  295. {
  296. ODS( L"CServerView::OnTabbed " );
  297. if( m_pTabs != NULL )
  298. {
  299. CWinAdminDoc *pDoc = (CWinAdminDoc*)GetDocument();
  300. if( pDoc != NULL )
  301. {
  302. FOCUS_STATE nFocus = pDoc->GetLastRegisteredFocus( );
  303. //
  304. // treeview should've started off with initial focus
  305. // we should
  306. if( nFocus == TREE_VIEW )
  307. {
  308. ODS( L"from tree to tab\n" );
  309. int nTab = m_pTabs->GetCurSel();
  310. m_pTabs->SetFocus( );
  311. m_pTabs->SetCurFocus( nTab );
  312. pDoc->RegisterLastFocus( TAB_CTRL );
  313. }
  314. else if( nFocus == TAB_CTRL )
  315. {
  316. ODS( L"from tab to item\n" );
  317. // set focus to item in page
  318. pages[ m_CurrPage ].m_pPage->SetFocus( );
  319. pDoc->RegisterLastFocus( PAGED_ITEM );
  320. }
  321. else
  322. {
  323. ODS( L"from item to treeview\n" );
  324. // set focus back to treeview
  325. CFrameWnd *p = (CFrameWnd*)pDoc->GetMainWnd();
  326. p->SendMessage( WM_FORCE_TREEVIEW_FOCUS , 0 , 0 );
  327. pDoc->RegisterLastFocus( TREE_VIEW );
  328. }
  329. pDoc->SetPrevFocus( nFocus );
  330. }
  331. }
  332. return 0;
  333. }
  334. //=-------------------------------------------------------------------------
  335. // OnShiftTabbed is called when the user wants to go back one
  336. // this code is duplicated in all view classes
  337. LRESULT CServerView::OnShiftTabbed( WPARAM , LPARAM )
  338. {
  339. ODS( L"CServerView::OnShiftTabbed " );
  340. if( m_pTabs != NULL )
  341. {
  342. CWinAdminDoc *pDoc = (CWinAdminDoc*)GetDocument();
  343. if( pDoc != NULL )
  344. {
  345. FOCUS_STATE nFocus = pDoc->GetLastRegisteredFocus( );
  346. switch( nFocus )
  347. {
  348. case TREE_VIEW:
  349. ODS( L"going back from tree to paged item\n" );
  350. pages[ m_CurrPage ].m_pPage->SetFocus( );
  351. pDoc->RegisterLastFocus( PAGED_ITEM );
  352. break;
  353. case TAB_CTRL:
  354. {
  355. ODS( L"going back from tab to treeview\n" );
  356. CFrameWnd *p = (CFrameWnd*)pDoc->GetMainWnd();
  357. p->SendMessage( WM_FORCE_TREEVIEW_FOCUS , 0 , 0 );
  358. pDoc->RegisterLastFocus( TREE_VIEW );
  359. }
  360. break;
  361. case PAGED_ITEM:
  362. {
  363. ODS( L"going back from paged item to tab\n" );
  364. int nTab = m_pTabs->GetCurSel();
  365. m_pTabs->SetFocus( );
  366. m_pTabs->SetCurFocus( nTab );
  367. pDoc->RegisterLastFocus( TAB_CTRL );
  368. }
  369. break;
  370. }
  371. pDoc->SetPrevFocus( nFocus );
  372. }
  373. }
  374. return 0;
  375. }
  376. //=-------------------------------------------------------------------------
  377. // ctrl + tab works the same as tab but because of our unorthodox ui
  378. // when under a tab control it will cycle over the tabs and back to the treeview
  379. //
  380. LRESULT CServerView::OnCtrlTabbed( WPARAM , LPARAM )
  381. {
  382. ODS( L"CServerView::OnCtrlTabbed " );
  383. int nTab;
  384. int nMaxTab;
  385. if( m_pTabs != NULL )
  386. {
  387. CWinAdminDoc *pDoc = (CWinAdminDoc*)GetDocument();
  388. if( pDoc != NULL )
  389. {
  390. FOCUS_STATE nFocus = pDoc->GetLastRegisteredFocus( );
  391. if( nFocus == TREE_VIEW )
  392. {
  393. ODS( L"from tree to tab\n" );
  394. nTab = m_pTabs->GetCurSel();
  395. nMaxTab = m_pTabs->GetItemCount( );
  396. if( nTab >= nMaxTab - 1 )
  397. {
  398. m_pTabs->SetCurSel( 0 );
  399. OnChangePage( 0 , 0 );
  400. nTab = 0;
  401. }
  402. m_pTabs->SetFocus( );
  403. m_pTabs->SetCurFocus( nTab );
  404. pDoc->RegisterLastFocus( TAB_CTRL );
  405. }
  406. else
  407. {
  408. nTab = m_pTabs->GetCurSel();
  409. nMaxTab = m_pTabs->GetItemCount( );
  410. if( nTab >= nMaxTab - 1 )
  411. {
  412. ODS( L"...back to treeview\n" );
  413. CFrameWnd *p = (CFrameWnd*)pDoc->GetMainWnd();
  414. p->SendMessage( WM_FORCE_TREEVIEW_FOCUS , 0 , 0 );
  415. pDoc->RegisterLastFocus( TREE_VIEW );
  416. }
  417. else
  418. {
  419. ODS( L" ...next tab...\n" );
  420. m_pTabs->SetCurSel( nTab + 1 );
  421. OnChangePage( 0 , 0 );
  422. m_pTabs->SetFocus( );
  423. m_pTabs->SetCurFocus( nTab + 1 );
  424. }
  425. }
  426. pDoc->SetPrevFocus( nFocus );
  427. }
  428. }
  429. return 0;
  430. }
  431. //=----------------------------------------------------------------------------
  432. // same as OnCtrlTab but we focus on moving in the other direction
  433. // tree_view to last tab -- current tab to ct - 1
  434. //
  435. LRESULT CServerView::OnCtrlShiftTabbed( WPARAM , LPARAM )
  436. {
  437. ODS( L"CServerView::OnCtrlShiftTabbed " );
  438. int nTab;
  439. int nMaxTab;
  440. if( m_pTabs != NULL )
  441. {
  442. CWinAdminDoc *pDoc = (CWinAdminDoc*)GetDocument();
  443. if( pDoc != NULL )
  444. {
  445. FOCUS_STATE nFocus = pDoc->GetLastRegisteredFocus( );
  446. if( nFocus == TREE_VIEW )
  447. {
  448. ODS( L"from tree to tab\n" );
  449. nMaxTab = m_pTabs->GetItemCount( );
  450. m_pTabs->SetCurSel( nMaxTab - 1 );
  451. OnChangePage( 0 , 0 );
  452. m_pTabs->SetFocus( );
  453. m_pTabs->SetCurFocus( nMaxTab - 1 );
  454. pDoc->RegisterLastFocus( TAB_CTRL );
  455. }
  456. else
  457. {
  458. nTab = m_pTabs->GetCurSel();
  459. nMaxTab = m_pTabs->GetItemCount( );
  460. if( nTab > 0 )
  461. {
  462. ODS( L" ...next tab...\n" );
  463. m_pTabs->SetCurSel( nTab - 1 );
  464. OnChangePage( 0 , 0 );
  465. m_pTabs->SetFocus( );
  466. m_pTabs->SetCurFocus( nTab - 1 );
  467. }
  468. else
  469. {
  470. ODS( L"...back to treeview\n" );
  471. CFrameWnd *p = (CFrameWnd*)pDoc->GetMainWnd();
  472. p->SendMessage( WM_FORCE_TREEVIEW_FOCUS , 0 , 0 );
  473. pDoc->RegisterLastFocus( TREE_VIEW );
  474. }
  475. }
  476. pDoc->SetPrevFocus( nFocus );
  477. }
  478. }
  479. return 0;
  480. }
  481. //=----------------------------------------------------------------------------
  482. // When the user hits F6 we need to switch between pains
  483. LRESULT CServerView::OnNextPane( WPARAM , LPARAM )
  484. {
  485. ODS( L"CServerView::OnNextPane\n" );
  486. int nTab;
  487. int nMaxTab;
  488. if( m_pTabs != NULL )
  489. {
  490. CWinAdminDoc *pDoc = (CWinAdminDoc*)GetDocument();
  491. if( pDoc != NULL )
  492. {
  493. FOCUS_STATE nFocus = pDoc->GetLastRegisteredFocus( );
  494. FOCUS_STATE nPrevFocus = pDoc->GetPrevFocus( );
  495. if( nFocus == TREE_VIEW )
  496. {
  497. if( nPrevFocus == TAB_CTRL )
  498. {
  499. nTab = m_pTabs->GetCurSel();
  500. m_pTabs->SetFocus( );
  501. m_pTabs->SetCurFocus( nTab );
  502. pDoc->RegisterLastFocus( TAB_CTRL );
  503. }
  504. else
  505. {
  506. pages[ m_CurrPage ].m_pPage->SetFocus( );
  507. pDoc->RegisterLastFocus( PAGED_ITEM );
  508. }
  509. }
  510. else
  511. {
  512. CFrameWnd *p = (CFrameWnd*)pDoc->GetMainWnd();
  513. p->SendMessage( WM_FORCE_TREEVIEW_FOCUS , 0 , 0 );
  514. pDoc->RegisterLastFocus( TREE_VIEW );
  515. }
  516. pDoc->SetPrevFocus( nFocus );
  517. }
  518. }
  519. return 0;
  520. }