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.

681 lines
16 KiB

  1. /****************************************************************************
  2. *
  3. * FILE: StatBar.cpp
  4. *
  5. * CREATED: Chris Pirich (ChrisPi) 3-25-96
  6. *
  7. * CONTENTS: CConfStatusBar object
  8. *
  9. ****************************************************************************/
  10. #include "precomp.h"
  11. #include "resource.h"
  12. #include "statbar.h"
  13. #include "NmLdap.h"
  14. #include "call.h"
  15. #include "cr.h"
  16. #include "confwnd.h"
  17. #include "ConfPolicies.h"
  18. static inline void TT_AddToolInfo(HWND hwnd, TOOLINFO *pti)
  19. {
  20. SendMessage(hwnd, TTM_ADDTOOL, 0, reinterpret_cast<LPARAM>(pti));
  21. }
  22. static inline void TT_GetToolInfo(HWND hwnd, TOOLINFO *pti)
  23. {
  24. SendMessage(hwnd, TTM_GETTOOLINFO, 0, reinterpret_cast<LPARAM>(pti));
  25. }
  26. static inline void TT_SetToolInfo(HWND hwnd, TOOLINFO *pti)
  27. {
  28. SendMessage(hwnd, TTM_SETTOOLINFO, 0, reinterpret_cast<LPARAM>(pti));
  29. }
  30. // Status Bar area indexes
  31. enum
  32. {
  33. ID_SBP_TEXT,
  34. // ID_SBP_ULS,
  35. ID_SBP_ICON,
  36. NUM_STATUSBAR_WELLS
  37. } ;
  38. // Status Bar area measurements (pixels)
  39. static const UINT DXP_SB_PROG = 96;
  40. static const UINT DXP_SB_ULS = 0; // 220;
  41. static const UINT DXP_SB_ICON = 22;
  42. static const UINT DXP_SB_DEF_ICON = 40;
  43. static const int IconBorder = 2;
  44. static const int StatSepBorder = 2;
  45. CConfStatusBar * CConfStatusBar::m_pStatusBar = NULL;
  46. /****************************************************************************
  47. *
  48. * CLASS: CConfStatusBar
  49. *
  50. * MEMBER: CConfStatusBar
  51. *
  52. * PURPOSE: Constructs object
  53. *
  54. ****************************************************************************/
  55. CConfStatusBar::CConfStatusBar(CConfRoom* pcr) :
  56. m_pcrParent (pcr),
  57. m_fVisible (FALSE),
  58. m_hwnd (NULL)
  59. {
  60. DebugEntry(CConfStatusBar::CConfStatusBar);
  61. ASSERT(NULL == m_pStatusBar);
  62. m_pStatusBar = this;
  63. m_szULSStatus[0] = _T('\0');
  64. for (int i=0; i<StatIconCount; ++i)
  65. {
  66. m_hIconStatus[i] = NULL;
  67. m_idIconStatus[i] = 0;
  68. }
  69. DebugExitVOID(CConfStatusBar::CConfStatusBar);
  70. }
  71. /****************************************************************************
  72. *
  73. * CLASS: CConfStatusBar
  74. *
  75. * MEMBER: !CConfStatusBar
  76. *
  77. * PURPOSE: Destructs object
  78. *
  79. ****************************************************************************/
  80. CConfStatusBar::~CConfStatusBar()
  81. {
  82. DebugEntry(CConfStatusBar::~CConfStatusBar);
  83. if (NULL != m_hwnd)
  84. {
  85. ::DestroyWindow(m_hwnd);
  86. }
  87. m_pStatusBar = NULL;
  88. for (int i=0; i<StatIconCount; ++i)
  89. {
  90. if (NULL != m_hIconStatus[i])
  91. {
  92. DestroyIcon(m_hIconStatus[i]);
  93. }
  94. }
  95. DebugExitVOID(CConfStatusBar::~CConfStatusBar);
  96. }
  97. /****************************************************************************
  98. *
  99. * CLASS: CConfStatusBar
  100. *
  101. * MEMBER: OnDraw(LPDRAWITEMSTRUCT pdis)
  102. *
  103. * PURPOSE: Handles drawing the status bar icon
  104. *
  105. ****************************************************************************/
  106. BOOL CConfStatusBar::OnDraw(LPDRAWITEMSTRUCT pdis)
  107. {
  108. ASSERT(pdis);
  109. if (NULL != (pdis->itemData))
  110. {
  111. int nLeft = pdis->rcItem.left;
  112. int nTop = pdis->rcItem.top;
  113. int xSmIcon = ::GetSystemMetrics(SM_CXSMICON);
  114. int ySmIcon = ::GetSystemMetrics(SM_CYSMICON);
  115. int nWidth = xSmIcon;
  116. int nHeight = pdis->rcItem.bottom - pdis->rcItem.top;
  117. if (nHeight > ySmIcon)
  118. {
  119. nTop += (nHeight - ySmIcon) / 2;
  120. nHeight = ySmIcon;
  121. }
  122. for (int i=0; i<StatIconCount; ++i)
  123. {
  124. nLeft += IconBorder;
  125. if (NULL != m_hIconStatus[i])
  126. {
  127. ::DrawIconEx( pdis->hDC,
  128. nLeft,
  129. nTop,
  130. m_hIconStatus[i],
  131. nWidth,
  132. nHeight,
  133. 0,
  134. NULL,
  135. DI_NORMAL);
  136. }
  137. nLeft += xSmIcon;
  138. }
  139. }
  140. return TRUE;
  141. }
  142. VOID CConfStatusBar::ForwardSysChangeMsg(UINT uMsg, WPARAM wParam, LPARAM lParam)
  143. {
  144. if (NULL == m_hwnd)
  145. return;
  146. ::SendMessage(m_hwnd, uMsg, wParam, lParam);
  147. }
  148. /****************************************************************************
  149. *
  150. * CLASS: CConfStatusBar
  151. *
  152. * MEMBER: Resize(WPARAM wParam, LPARAM lParam)
  153. *
  154. * PURPOSE: Handles window resizing
  155. *
  156. ****************************************************************************/
  157. VOID CConfStatusBar::Resize(WPARAM wParam, LPARAM lParam)
  158. {
  159. if (NULL != m_hwnd)
  160. {
  161. ::SendMessage(m_hwnd, WM_SIZE, wParam, lParam);
  162. ResizeParts();
  163. }
  164. }
  165. /****************************************************************************
  166. *
  167. * CLASS: CConfStatusBar
  168. *
  169. * MEMBER: Create(HWND hwndParent)
  170. *
  171. * PURPOSE: Creates the status bar window
  172. *
  173. ****************************************************************************/
  174. BOOL CConfStatusBar::Create(HWND hwndParent)
  175. {
  176. DebugEntry(CConfStatusBar::Create);
  177. BOOL bRet = FALSE;
  178. m_hwnd = CreateStatusWindow(WS_CHILD | WS_BORDER,
  179. g_szEmpty,
  180. hwndParent,
  181. ID_STATUS);
  182. if (NULL != m_hwnd)
  183. {
  184. // Create the ToolTip
  185. m_hwndLoginTT = CreateWindowEx(0,
  186. TOOLTIPS_CLASS,
  187. (LPSTR) NULL,
  188. 0, // styles
  189. CW_USEDEFAULT,
  190. CW_USEDEFAULT,
  191. CW_USEDEFAULT,
  192. CW_USEDEFAULT,
  193. m_hwnd,
  194. (HMENU) NULL,
  195. ::GetInstanceHandle(),
  196. NULL);
  197. // Add the ToolTips for the 2 icons
  198. if (NULL != m_hwndLoginTT)
  199. {
  200. TOOLINFO ti;
  201. ti.cbSize = sizeof(TOOLINFO);
  202. ti.hwnd = m_hwnd;
  203. ti.hinst = ::GetInstanceHandle();
  204. ti.lpszText = const_cast<LPTSTR>(g_szEmpty);
  205. SetRect(&ti.rect, 0, 0, 0, 0);
  206. for (UINT i=0; i<StatIconCount; ++i)
  207. {
  208. ti.uId = i;
  209. ti.uFlags = TTF_SUBCLASS;
  210. TT_AddToolInfo(m_hwndLoginTT, &ti);
  211. }
  212. }
  213. // create progress meter window
  214. ResizeParts();
  215. Update();
  216. bRet = TRUE;
  217. }
  218. else
  219. {
  220. WARNING_OUT(("CConfStatusBar::Create - Unable to create status window"));
  221. }
  222. DebugExitBOOL(CConfStatusBar::Create, bRet);
  223. return bRet;
  224. }
  225. /****************************************************************************
  226. *
  227. * CLASS: CConfStatusBar
  228. *
  229. * FUNCTION: ResizeParts()
  230. *
  231. * PURPOSE: Calculates the correct size of the status bar parts
  232. *
  233. ****************************************************************************/
  234. VOID CConfStatusBar::ResizeParts()
  235. {
  236. ASSERT(m_hwnd);
  237. int xSmIcon = ::GetSystemMetrics(SM_CXSMICON);
  238. #ifdef RESIZEABLE_WINDOW
  239. UINT uIconPartWidth = DXP_SB_DEF_ICON;
  240. NONCLIENTMETRICS ncm;
  241. ncm.cbSize = sizeof(ncm);
  242. if (::SystemParametersInfo( SPI_GETNONCLIENTMETRICS,
  243. 0,
  244. &ncm,
  245. 0))
  246. {
  247. m_nScrollWidth = ncm.iScrollWidth;
  248. uIconPartWidth = DXP_SB_ICON + m_nScrollWidth;
  249. }
  250. #else // RESIZEABLE_WINDOW
  251. // Room for 2 icons
  252. UINT uIconPartWidth = StatSepBorder + IconBorder + xSmIcon
  253. + IconBorder + xSmIcon + IconBorder + StatSepBorder;
  254. #endif // RESIZEABLE_WINDOW
  255. // re-calculate positions of each tray part
  256. RECT rc;
  257. ::GetWindowRect(m_hwnd, &rc);
  258. DWORD dxp = rc.right - rc.left;
  259. if (dxp > uIconPartWidth)
  260. {
  261. DWORD rgPos[NUM_STATUSBAR_WELLS]; // right edge positions for each part
  262. rgPos[ID_SBP_TEXT] = dxp - (DXP_SB_ULS + uIconPartWidth);
  263. // rgPos[ID_SBP_ULS] = dxp - uIconPartWidth;
  264. rgPos[ID_SBP_ICON] = (DWORD) -1;
  265. ::SendMessage( m_hwnd,
  266. SB_SETPARTS,
  267. (WPARAM) ARRAY_ELEMENTS(rgPos),
  268. (LPARAM) &rgPos);
  269. if (m_hwndLoginTT)
  270. {
  271. TCHAR szTitle[MAX_PATH];
  272. TOOLINFO ti;
  273. ti.cbSize = sizeof(TOOLINFO);
  274. ti.hwnd = m_hwnd;
  275. int nIconsLeft = dxp - uIconPartWidth + StatSepBorder + IconBorder;
  276. for (UINT i=0; i<StatIconCount; ++i)
  277. {
  278. ti.uId = i;
  279. ti.lpszText = szTitle;
  280. TT_GetToolInfo(m_hwndLoginTT, &ti);
  281. // HACKHACK georgep: Just setting the height to a large number, since
  282. // I don't know exactly where the icon will be drawn until it is drawn
  283. SetRect(&ti.rect, nIconsLeft, 0, nIconsLeft + xSmIcon, 1000);
  284. ti.uFlags = TTF_SUBCLASS;
  285. TT_SetToolInfo(m_hwndLoginTT, &ti);
  286. nIconsLeft += xSmIcon + IconBorder;
  287. }
  288. }
  289. }
  290. }
  291. void CConfStatusBar::SetTooltip(StatIcon eIcon, LPCTSTR szTip)
  292. {
  293. TCHAR szTitle[MAX_PATH];
  294. TOOLINFO ti;
  295. ti.cbSize = sizeof(TOOLINFO);
  296. ti.hwnd = m_hwnd;
  297. ti.lpszText = szTitle;
  298. ti.uId = eIcon;
  299. TT_GetToolInfo(m_hwndLoginTT, &ti);
  300. ti.lpszText = const_cast<LPTSTR>(szTip);
  301. ti.uFlags = TTF_SUBCLASS;
  302. TT_SetToolInfo(m_hwndLoginTT, &ti);
  303. }
  304. /****************************************************************************
  305. *
  306. * CLASS: CConfStatusBar
  307. *
  308. * MEMBER: RemoveHelpText()
  309. *
  310. * PURPOSE: Removes the status bar help text
  311. *
  312. ****************************************************************************/
  313. VOID CConfStatusBar::RemoveHelpText()
  314. {
  315. // Taking status bar out of simple mode
  316. if (NULL != m_hwnd)
  317. {
  318. ::SendMessage(m_hwnd, SB_SIMPLE, FALSE, 0);
  319. }
  320. }
  321. /****************************************************************************
  322. *
  323. * CLASS: CConfStatusBar
  324. *
  325. * MEMBER: SetHelpText(LPCTSTR pcszText)
  326. *
  327. * PURPOSE: Sets the status bar help text
  328. *
  329. ****************************************************************************/
  330. VOID CConfStatusBar::SetHelpText(LPCTSTR pcszText)
  331. {
  332. // Putting status bar into simple mode
  333. if (NULL != m_hwnd)
  334. {
  335. ::SendMessage(m_hwnd, SB_SIMPLE, TRUE, 0);
  336. // 255 means simple mode - only 1 pane
  337. ::SendMessage( m_hwnd,
  338. SB_SETTEXT,
  339. 255 | SBT_NOBORDERS,
  340. (LPARAM) pcszText);
  341. }
  342. }
  343. /****************************************************************************
  344. *
  345. * CLASS: CConfStatusBar
  346. *
  347. * MEMBER: Show(BOOL fShow)
  348. *
  349. * PURPOSE: Handles the toggling of the status bar window
  350. *
  351. ****************************************************************************/
  352. VOID CConfStatusBar::Show(BOOL fShow)
  353. {
  354. DebugEntry(CConfStatusBar::Show);
  355. fShow = fShow != FALSE;
  356. if (m_fVisible != fShow)
  357. {
  358. m_fVisible = fShow;
  359. if (NULL != m_hwnd)
  360. {
  361. ::ShowWindow(m_hwnd, m_fVisible ? SW_SHOW : SW_HIDE);
  362. }
  363. // Force a resize
  364. ResizeParts();
  365. }
  366. DebugExitVOID(CConfStatusBar::Show);
  367. }
  368. /****************************************************************************
  369. *
  370. * CLASS: CConfStatusBar
  371. *
  372. * MEMBER: GetHeight()
  373. *
  374. * PURPOSE: Returns the height in pixels of the status bar
  375. *
  376. ****************************************************************************/
  377. int CConfStatusBar::GetHeight()
  378. {
  379. RECT rc = {0, 0, 0, 0};
  380. if (m_fVisible && (NULL != m_hwnd))
  381. {
  382. GetWindowRect(m_hwnd, &rc);
  383. }
  384. return (rc.bottom - rc.top);
  385. }
  386. /****************************************************************************
  387. *
  388. * CLASS: CConfStatusBar
  389. *
  390. * MEMBER: SetIcon(DWORD dwId)
  391. *
  392. * PURPOSE: Set the status bar icon
  393. *
  394. ****************************************************************************/
  395. VOID CConfStatusBar::SetIcon(StatIcon eIcon, DWORD dwId)
  396. {
  397. DWORD &idIconStatus = m_idIconStatus[eIcon];
  398. HICON &hIconStatus = m_hIconStatus [eIcon];
  399. if ((NULL != m_hwnd) && (dwId != idIconStatus))
  400. {
  401. TRACE_OUT(("Changing Icon from %d to %d", m_idIconStatus, dwId));
  402. // REVIEW: what happens to old m_hIconStatus?
  403. HICON hIcon = (HICON) ::LoadImage(::GetInstanceHandle(),
  404. MAKEINTRESOURCE(dwId),
  405. IMAGE_ICON,
  406. ::GetSystemMetrics(SM_CXSMICON),
  407. ::GetSystemMetrics(SM_CYSMICON),
  408. LR_DEFAULTCOLOR);
  409. if (NULL != hIcon)
  410. {
  411. idIconStatus = dwId;
  412. if (NULL != hIconStatus)
  413. {
  414. ::DestroyIcon(hIconStatus);
  415. }
  416. hIconStatus = hIcon;
  417. ::SendMessage( m_hwnd,
  418. SB_SETTEXT,
  419. ID_SBP_ICON | SBT_OWNERDRAW,
  420. (LPARAM) hIconStatus);
  421. }
  422. else
  423. {
  424. WARNING_OUT(("Unable to load status bar icon id=%d", dwId));
  425. }
  426. }
  427. }
  428. /****************************************************************************
  429. *
  430. * CLASS: CConfStatusBar
  431. *
  432. * MEMBER: SetText(UINT uID, LPCTSTR pcszText)
  433. *
  434. * PURPOSE: Set the status bar text
  435. *
  436. ****************************************************************************/
  437. VOID CConfStatusBar::SetText(UINT uID, LPCTSTR pcszText)
  438. {
  439. lstrcpyn( m_szULSStatus, pcszText, CCHMAX(m_szULSStatus) );
  440. if (NULL != m_hwnd)
  441. {
  442. ::SendMessage(m_hwnd, SB_SETTEXT, uID, (LPARAM) pcszText);
  443. }
  444. }
  445. /****************************************************************************
  446. *
  447. * CLASS: CConfStatusBar
  448. *
  449. * FUNCTION: Update()
  450. *
  451. * PURPOSE: Updates the status bar
  452. *
  453. ****************************************************************************/
  454. VOID CConfStatusBar::Update()
  455. {
  456. DBGENTRY(CConfStatusBar::Update);
  457. ASSERT(m_pcrParent);
  458. if (!m_fVisible)
  459. return;
  460. TCHAR szCallStatus[ MAX_PATH * 3 ]; // Call status is status + url and url can be 512 by itself...
  461. UINT uCallIcon = 0;
  462. DWORD dwCallTick = 0;
  463. if (0 == dwCallTick)
  464. {
  465. // no current calls - check if switching a/v
  466. dwCallTick = GetCallStatus(szCallStatus, CCHMAX(szCallStatus), &uCallIcon);
  467. }
  468. // if a call was started more recently than any other action, OR nothing is going on
  469. // (in which case all ticks should equal zero), use the conference / call status
  470. if (dwCallTick == 0)
  471. {
  472. // All ticks are zero - Get the default conference status bar info
  473. m_pcrParent->GetConferenceStatus(szCallStatus, CCHMAX(szCallStatus), &uCallIcon);
  474. }
  475. SetText(ID_SBP_TEXT, szCallStatus);
  476. SetIcon(StatConnect, uCallIcon);
  477. SetTooltip(StatConnect, szCallStatus);
  478. TCHAR szOldULSStatus[ARRAY_ELEMENTS(m_szULSStatus)];
  479. lstrcpy(szOldULSStatus, m_szULSStatus);
  480. switch( g_GkLogonState )
  481. {
  482. case NM_GK_IDLE:
  483. uCallIcon = IDI_NETGRAY;
  484. lstrcpy(m_szULSStatus, RES2T(ID_STATUS_NOT_LOGGED_ON_TO_GATEKEEPER));
  485. break;
  486. case NM_GK_LOGGING_ON:
  487. uCallIcon = IDS_STATUS_WAITING;
  488. lstrcpy(m_szULSStatus, RES2T(ID_STATUS_LOGING_ONTO_GATEKEEPER));
  489. break;
  490. case NM_GK_LOGGED_ON:
  491. uCallIcon = IDI_NET;
  492. lstrcpy(m_szULSStatus, RES2T(ID_STATUS_LOGGED_ONTO_GATEKEEPER));
  493. break;
  494. default:
  495. uCallIcon = IDI_NETGRAY;
  496. if(ConfPolicies::CallingMode_Direct == ConfPolicies::GetCallingMode())
  497. {
  498. if(g_pLDAP)
  499. {
  500. g_pLDAP->GetStatusText(m_szULSStatus, CCHMAX(m_szULSStatus), &uCallIcon);
  501. }
  502. else
  503. {
  504. lstrcpy(m_szULSStatus, RES2T(ID_STATUS_LOGGEDOFF));
  505. }
  506. }
  507. else
  508. {
  509. lstrcpy(m_szULSStatus, RES2T(ID_STATUS_NOT_LOGGED_ON_TO_GATEKEEPER));
  510. }
  511. break;
  512. }
  513. if (lstrcmp(szOldULSStatus, m_szULSStatus))
  514. {
  515. SetTooltip(StatLogin, m_szULSStatus);
  516. }
  517. SetIcon(StatLogin, uCallIcon);
  518. ::UpdateWindow(m_hwnd);
  519. }
  520. /* F O R C E S T A T U S B A R U P D A T E */
  521. /*-------------------------------------------------------------------------
  522. %%Function: ForceStatusBarUpdate
  523. Force an update of the status bar.
  524. This can be called from any thread.
  525. All main UI updates should be done from the main thread.
  526. -------------------------------------------------------------------------*/
  527. VOID ForceStatusBarUpdate(void)
  528. {
  529. CConfRoom * pcr = ::GetConfRoom();
  530. if (NULL != pcr)
  531. {
  532. PostMessage(pcr->GetTopHwnd(), WM_STATUSBAR_UPDATE, 0, 0);
  533. }
  534. }
  535. ///////////////////////////////////////////////////////////////////////////
  536. /* C M D V I E W S T A T U S B A R */
  537. /*-------------------------------------------------------------------------
  538. %%Function: CmdViewStatusBar
  539. -------------------------------------------------------------------------*/
  540. VOID CmdViewStatusBar(void)
  541. {
  542. CConfStatusBar * pStatusBar = CConfStatusBar::GetInstance();
  543. if (NULL == pStatusBar)
  544. return;
  545. CConfRoom * pcr = ::GetConfRoom();
  546. if (NULL == pcr)
  547. return;
  548. HWND hwnd = pcr->GetTopHwnd();
  549. // Turn off redraws:
  550. ::SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
  551. // Toggle visibility
  552. pStatusBar->Show(!pStatusBar->FVisible());
  553. ::SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
  554. pcr->ForceWindowResize();
  555. UpdateUI(CRUI_STATUSBAR);
  556. }
  557. /* C H E C K M E N U _ V I E W S T A T U S B A R */
  558. /*-------------------------------------------------------------------------
  559. %%Function: CheckMenu_ViewStatusBar
  560. -------------------------------------------------------------------------*/
  561. BOOL CheckMenu_ViewStatusBar(HMENU hMenu)
  562. {
  563. BOOL fCheck = FALSE;
  564. CConfStatusBar * pStatusBar = CConfStatusBar::GetInstance();
  565. if (NULL != pStatusBar)
  566. {
  567. fCheck = pStatusBar->FVisible();
  568. if (NULL != hMenu)
  569. {
  570. ::CheckMenuItem(hMenu, IDM_VIEW_STATUSBAR,
  571. fCheck ? MF_CHECKED : MF_UNCHECKED);
  572. }
  573. }
  574. return fCheck;
  575. }